Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何手动模拟更改触发器,而不是使用$(object).change();或$(object.bind(';change';)或$(object.trigger(';change';)_Javascript_Jquery_Onchange - Fatal编程技术网

Javascript 如何手动模拟更改触发器,而不是使用$(object).change();或$(object.bind(';change';)或$(object.trigger(';change';)

Javascript 如何手动模拟更改触发器,而不是使用$(object).change();或$(object.bind(';change';)或$(object.trigger(';change';),javascript,jquery,onchange,Javascript,Jquery,Onchange,我想模拟改变触发器。我想在最后触发我的更改代码。我想更改所有未禁用的输入 $('selector').load().each(function () { if ((typeof $(this).attr("VALUE") != 'undefined') && ($(this).attr("disabled") != 'disabled')) { //do something ... //then I want to simulate Tri

我想模拟改变触发器。我想在最后触发我的更改代码。我想更改所有未禁用的输入

$('selector').load().each(function () {
    if ((typeof $(this).attr("VALUE") != 'undefined') && ($(this).attr("disabled") != 'disabled')) {
        //do something ...
        //then I want to simulate Trigger with something like that:
        $(this).val(0);
        $(this).val(tmp);
        //here i want code, that will triger my code on the end 

    }
    $("selector").bind('change', function () {
        // alert("change");
        CF_change($(this), "CF", clientCulture);
        SaveData($(this).attr('id'), $(this).attr('str_id'), $(this).val(), 0, '');
    });
}

您可以通过以下方式触发事件:

$("your_selector").change();

为什么要排除触发绑定到元素的事件处理程序的所有官方方法?我认为@nataly的意思是他(她?)希望从代码中触发事件,而不是由用户触发。这完全没有意义。使用val()更改值不会触发事件,触发事件处理程序的唯一方法是实际更改某些内容或使用OP不想使用的方法之一,因此答案很简单,如果无法使用任何方法以编程方式触发事件,则不可能。+1因为,即使你没有通过阅读理解测试,你至少给出了正确的答案。很难理解OP写的是什么,我认为他想从代码中手动触发事件。我有一些非英语国家的人尝试用英语描述一些事情的经验,我认为这就是问题所在;)我们会在@nataly澄清他的问题时发现;)嗯,是的,我同意。阅读理解失败的原因是OP指定他不想在问题标题中使用
.change()
!对不起,我的英语不好,但是你说得对。我只是想模拟一下情况,当你进入输入时,改变值并触发改变事件。谢谢你。