onclick事件不适用于选项

编程入门 行业动态 更新时间:2024-10-22 10:59:29
本文介绍了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>

解决方案

options 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事件不适用于选项

本文发布于:2023-11-23 14:05:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621705.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项   不适用于   事件   onclick

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!