为什么 Toggled 值总是返回 OFF

发布于 2024-07-30 08:27:00 字数 1133 浏览 4 评论 0原文

我想通过切换来打开或关闭值。
默认值和视图是关闭的。
但该代码始终返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-08-06 08:27:00

这行代码没有效果:

$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';

意思是:

如果输入 ID search_withbydate 的值为“OFF”,则将输入 ID search_withbydate 的值设置为“OFF”,否则将输入 ID search_withbydate 的值设置为“ON”

尝试

$('search_withbydate').value = ($('search_withbydate').value == 'OFF') ? 'ON' : 'OFF';

:表示:

如果输入 ID search_withbydate 的值为“OFF”,则将输入 ID search_withbydate 的值设置为“ON”,否则将输入 ID search_withbydate 的值设置为“OFF”

This line of code has no effect:

$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';

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:

$('search_withbydate').value = ($('search_withbydate').value == 'OFF') ? 'ON' : 'OFF';

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"

木格 2024-08-06 08:27:00

为什么你用 iPhone 和 UIWebView 来标记这个问题? 这是一个 javascript/动态 HTML 问题。

接下来,您的实际问题是什么? 让我感到非常惊讶的是,您发布此内容的目的是希望有人可以帮助您。 你不仅不太懂Javascript,而且看起来你也不太懂英语。 ;-)

据我所知,您的 onclick 代码中的括号放错了位置。

改变这个:

($('search_withbydate').value == 'OFF' ? 'OFF' : 'ON';)

到这个

($('search_withbydate').value == 'OFF') ? 'OFF' : 'ON';

你看到区别了吗? 但是,由于名为“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:

($('search_withbydate').value == 'OFF' ? 'OFF' : 'ON';)

To this

($('search_withbydate').value == 'OFF') ? 'OFF' : 'ON';

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文