onclick事件不适用于选项 [英] The onclick event does not work for options
本文介绍了onclick事件不适用于选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的代码,它可以在Firefox中正常工作,但不在Chrome中。
请让我知道如何解决这个问题。主要思想是根据选择框的选定值调用js函数:
< select onselect =question_type( THIS.VALUE); name =qtypeid =qtypeclass =form-control input-lgrequired>
< option value => - 为此测验选择问题类型 - < / option>
< option onclick =question_type(this.value);值=mcq> 1)MCQ< / option>
< option onclick =question_type(this.value); value =tf> 2)True / False< / option>
< / select>
解决方案
选项
对于选择
元素,您可以使用 onchange
事件在选择本身,并且选择的值将始终与选定的选项相同
< select onchange =question_type(this.value); name =qtypeid =qtypeclass =form-control input-lgrequired>
< option value => - 为此测验选择问题类型 - < / option>
< option value =mcq> 1)MCQ< / option>
< option value =tf> 2)True / False< / option>
< / select>
使用jQuery它会是
<$ p $ ('change',function(){
var selected = this.value;
});
Following is my code which works fine in firefox but not in chrome. Kindly let me know how to solve this issue. The main idea is to call a js function based on the selected value of select box:
<select onselect="question_type(this.value);" name="qtype" id="qtype" class="form-control input-lg" required>
<option value="">-- Select question type for this quiz --</option>
<option onclick="question_type(this.value);" value="mcq">1) MCQs</option>
<option onclick="question_type(this.value);" value="tf">2) True/False</option>
</select>
解决方案
option
s don't fire mouse events in chrome.
For a select
element you'd use the onchange
event on the select itself, and the value of the select will always be the same as the selected option
<select onchange="question_type(this.value);" name="qtype" id="qtype" class="form-control input-lg" required>
<option value="">-- Select question type for this quiz --</option>
<option value="mcq">1) MCQs</option>
<option value="tf">2) True/False</option>
</select>
with jQuery it would be
$('select').on('change', function() {
var selected = this.value;
});
这篇关于onclick事件不适用于选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文