简体   繁体   中英

onchange does not work

I have this code

<select id="priority" onchange="myfunction(10);">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>

and what i don't understand that it does not trigger the event on the change of the select tag. Why is that?

You've told jsfiddle to put your JavaScript code inside a "load" handler. Thus, your function isn't global and won't be found when the element changes.

Change the pulldown that currently says "onLoad" to either "no wrap (head)" or "no wrap (body)".

If you want to stick to your own code, then you have to change the handler on jsFiddle as mentioned by @Pointy. But if you want it to be done in another way, then try it as below.

javaScript :

priority.onchange = function myfunction()
{
    alert("On change worked");
}

jQuery :

$("#priority").change({id : 10}, function(event){
    alert(event.data.id);
});

Demo

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM