为什么 Toggled 值总是返回 OFF
我想通过切换来打开或关闭值。
默认值和视图是关闭的。
但该代码始终返回 OFF。
<div id='toggl1'>
<fieldset>
<form id='search' method='post'>
<input id='search_withbydate' name='search_withbydate' type='hidden' value='OFF'>
<div class='row'>
<label>by date</label>
<div class='toggle' id='search_withbydate' onclick="$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';">
<span class='thumb'></span>
<span class='toggleOn'>ON</span>
<span class='toggleOff'>OFF</span>
</div>
</div>
</input>
<input type='submit' value='search' />
</form>
</fieldset>
</div>
我不太了解 javascript,我参考下面的章节。
5.10. 杂项运算符
5.10.1. 条件运算符 (?:)
JavaScript:权威指南,第五版
作者:大卫·弗拉纳根
发行商:奥莱利
谢谢。
tknv/
I would like to get value ON or OFF by toggled.
And default value and view is OFF.
But that code return always OFF.
<div id='toggl1'>
<fieldset>
<form id='search' method='post'>
<input id='search_withbydate' name='search_withbydate' type='hidden' value='OFF'>
<div class='row'>
<label>by date</label>
<div class='toggle' id='search_withbydate' onclick="$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';">
<span class='thumb'></span>
<span class='toggleOn'>ON</span>
<span class='toggleOff'>OFF</span>
</div>
</div>
</input>
<input type='submit' value='search' />
</form>
</fieldset>
</div>
I do not know javascript well,I refer that below Chapter.
5.10. Miscellaneous Operators
5.10.1. The Conditional Operator (?:)
JavaScript: The Definitive Guide, 5th Edition
By David Flanagan
Publisher: O'Reilly
Thanks.
tknv/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这行代码没有效果:
意思是:
如果输入 ID search_withbydate 的值为“OFF”,则将输入 ID search_withbydate 的值设置为“OFF”,否则将输入 ID search_withbydate 的值设置为“ON”
尝试
:表示:
如果输入 ID search_withbydate 的值为“OFF”,则将输入 ID search_withbydate 的值设置为“ON”,否则将输入 ID search_withbydate 的值设置为“OFF”
This line of code has no effect:
What that says is:
Set the value of input ID search_withbydate to "OFF" if the value of input ID search_withbydateis "OFF", otherwise set the value of input ID search_withbydate to "ON"
Try:
Which says:
Set the value of input ID search_withbydate to "ON" if the value of input ID search_withbydateis "OFF", otherwise set the value of input ID search_withbydate to "OFF"
为什么你用 iPhone 和 UIWebView 来标记这个问题? 这是一个 javascript/动态 HTML 问题。
接下来,您的实际问题是什么? 让我感到非常惊讶的是,您发布此内容的目的是希望有人可以帮助您。 你不仅不太懂Javascript,而且看起来你也不太懂英语。 ;-)
据我所知,您的 onclick 代码中的括号放错了位置。
改变这个:
到这个
你看到区别了吗? 但是,由于名为“search_withbydate”的输入属于“隐藏”类型,因此当您单击 div 时,您实际上不会看到任何更改,除非您使用 JavaScript 调试器,例如 Firebug(它是 Firefox 插件)。
这就是我能做的最好的事情了。 我建议您尝试重新表述您的想法,并用实际问题更新您的帖子。
Why did you tag this question with iPhone and UIWebView? This is a javascript/dynamic HTML question.
Next, what is your actual question? It's quite surprising to me that you've posted this with the expectation that someone can help you. You not only don't know Javascript very well, but it would appear that you don't know English very well either. ;-)
From what I can see you have a parentheses misplaced in your onclick code.
Change this:
To this
Do you see the difference? But because your input named 'search_withbydate' is of type 'hidden' you won't actually see a change when you click the div unless you use a javascript debugger such as Firebug (it's a Firefox plug-in).
That's about the best I can do. I suggest you try to reformulate your thoughts and update your post with an actual question.