【发布时间】:2016-05-03 02:18:47
【问题描述】:
我已经深入研究了一些类似的问题(这不是一个独特的问题),但许多只处理当前标签或更改标签以匹配选择。
我的 jQuery 技能相当一般:函数很好,但是链接它们(并且知道浏览器技巧......)有点棘手。
我的目标是:
- 用户从
<select>列表中选择“电子邮件”或“Web”。 - 基于此选择,我们更新下方
<input>的<label>及其下方<span>的内容(一些帮助文本,将有助于显示“http://yourdomain.com/here”或“stuff@yourdomain. com")
另外:
- 将输入字段的
type更改为type="email"或type="url"。来自what I can see,这可能是因为IE兼容问题? - 替代方法可能是 .show()/.hide() 两个输入(每种类型一个),而不是基于选择。
JSFiddle:http://jsfiddle.net/ys9Cj/(到目前为止:我一直在改变字段。就像我说的,JQuery 不太好!)
这是 HTML:
<label for="method">How?</label>
<select id="method" name="method" required>
<option name="method" value="email">Email</option>
<option name="method" value="web">Web</option>
</select>
<span class="help-text">The web, or email?</span>
</label>
<label for="contact">Email Address</label> // We want to update this (but not strictly with the value from the <select>
<input type="email" name="contact" id="contact" value="" maxlength="255"> // and the type here, or otherwise .show() or .hide() this and show an alternative field with a different name=""
<span class="help-text">e.g. stuff@yourdomain.com</span> // and change the contents here
【问题讨论】:
-
分享你用于上述场景的jquery代码..
-
为了让人们回答你的问题,你已经尝试简化你的问题..我看到这个问题后的第一印象是它太长了..问题更短更准确。 .更好的反应你会得到..
-
@Onaseriousnote 你的显示名让我笑了:)
-
尝试创建一个JSFiddle,它会更容易理解,展示你的尝试并得到答案
-
我添加了一个(部分!)JSFiddle。 @Onaseriousnote - 我试图在这里具体一点,因为我有一些要求。让我不必问一连串的问题! :)
标签: javascript jquery html