动态获取选定值,并在条件[关闭]时包含该值(Get selected value dynamically and include that in if condition [closed])

编程入门 行业动态 更新时间:2024-10-27 06:19:35
动态获取选定值,并在条件[关闭]时包含该值(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

更多推荐

本文发布于:2023-07-24 00:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   条件   动态   selected   closed

发布评论

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

>www.elefans.com

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