动态获取选定值,并在条件[关闭]时包含该值(Get selected value dynamically and include that in if condition [closed])
如何在不加载页面的情况下动态从选择框中获取值,并在if条件下使用该值?
How to get value from select box dynamically without loading page and use that value in if condition ?
最满意答案
“没有加载页面”
我猜你的意思是“没有提交表单”并重新加载页面,因为你显然无法在不加载页面的情况下获得页面上控件的值。
做这样的事情:
var val = $("#idOfSelectHere").val(); if (val === "something" || val === "something else") { // do something } else if (val === "whatever" && someOtherCondition) { // do whatever }显然你可以添加尽可能多的条件, else if你喜欢的话...
进一步阅读: jQuery的.val()方法
"without loading page"
I'm going to guess that you mean "without submitting the form" and reloading the page, since you obviously can't get the value of a control on a page without loading that page.
Just do something like this:
var val = $("#idOfSelectHere").val(); if (val === "something" || val === "something else") { // do something } else if (val === "whatever" && someOtherCondition) { // do whatever }Obviously you can add as many conditions and else ifs as you like...
Further reading: jQuery's .val() method
更多推荐
发布评论