I am using multiple-select.js, there when I set the value using setSelects method they are set the value and dynamically trigger the onchange function. But In my situation I want to disable this dynamically triggering. Also I can't able to modify the multiple-select.js because many one use this plugin in different module.
If I can detect is this onchange function is call from dynamically trigger or native dropdown change, my problem will solve. But don't use any global variable . Only we can use argument(may be we can use onchange="ddlchange(this)").
I am wrote a simple example like my problem
<script> function check(ths) { //Here I want to know is it come from real change or manually trigger, without using any variable alert("function called"); } function trifun() { //I can't modify this line, because it is in external plugin document.getElementById('ddl').onchange(); } </script> <button onclick="trifun();">Trigger</button> <select id="ddl" onchange="check(this);"> <option value="1">Test</option> <option value="2">Test</option> <option value="3">Test</option> <option value="4">Test</option> <option value="5">Test</option> </select>
this help you :
<html>
<head>
<title></title>
</head>
<body>
<script>
var trg = document.getElementById("ddl");
function check(ths,event)
{
//Here I want to know is it come from real change or manually trigger, without using any variable
if (event.type == "change")
alert("function called with Change");
else
alert("function called with click");
}
function trifun(event)
{
//I can't modify this line, because it is in external plugin
document.getElementById('ddl').onchange(event);
}
</script>
<button onclick="trifun(event);">Trigger</button>
<select id="ddl" onchange="check(this,event);">
<option value="1">Test</option>
<option value="2">Test</option>
<option value="3">Test</option>
<option value="4">Test</option>
<option value="5">Test</option>
</select>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.