我从这个SO问题中修改了一组简单的下拉选项。如果我在jQuery(不带JQM)中运行它,它将正常运行,当我添加jQuery Mobile时,HTML仅在页面上闪烁,然后变为空白,我不知道为什么。如果启用jQuery Mobile并注释掉JS的最后一行:
showTab(select.val());
它会显示所有可用的选择,而不是仅显示一个选择的预期结果。在下面的小提琴中,选择jQuery Mobile,然后运行它,HTML闪烁一秒钟后便消失了。
下面的工作小提琴将其显示为我想要的工作状态,在做出选择之后,仅显示由下拉列表选择的选择。但是我也希望jQuery Mobile也能正常工作。忽略“提交”按钮,它尚未连接任何东西。
HTML:
<form>
<p>
<h2>Select option to create PCBID:</h2>
<select id="dropdown" name="dropdown">
<option value="pcbids" selected="selected">PCBID Single</option>
<option value="pcbidr">PCBID Range</option>
<option value="pcbidq">PCBID Quantity</option>
<option value="pcbidl">PCBID List</option>
</select>
</p>
</form>
<body>
<div id="pcbids">
<label>PCBID Single:</label>
<input type="number" placeholder="12345" title="Just enter a single PCBID number" />
</div>
<div id="pcbidl">
<label>PCBID List:</label>
<input type="textarea" placeholder="12345,70237,8901" title="Enter a comma separated list of PCBID numbers you're like to create" />
</div>
<div id="pcbidr">
<label>PCBID Range:</label>
<input type="text" placeholder="12345-12400" title="Enter a range separated by a dash (-) and no spaces" />
</div>
<div id="pcbidq">
<label>PCBID Quantity:</label>
<input type="text" placeholder="12345:100" title="Enter a starting PCBID number followed by a colon (:), followed by the sequential number you want to create" />
</div>
<label for="submit"></label>
<input type="button" id="create_button" value="Submit" />
JS:
var select = $('#dropdown');
function showTab(name) {
name = '#' + name;
$('div').not(name).hide();
$(name).show();
}
select.change(function () {
showTab($(this).val());
});
//comment out this last line after selecting jQuery Mobile 1.3.1 under Frameworks & Extensions above
showTab(select.val());
我尝试将代码加载到中$(document.ready(function(){...}); construct
,以及$(window).load(function() {...});
第二个代码中,我都可以得到完整的选择列表,以在加载JQM时显示出来,但是一旦选择了一个,整个页面就会再次消失。
我想念什么?如果有什么不同,那就全在Chrome中了。作为参考,这是我修改过的原始提琴。
jQuery Mobile的每个包装input
和button
在保持所有样式核实。
使用时$('div').not(name).hide();
,您将隐藏页面中的每个div,包括input
包装器。但是,使用时.show()
,将显示父div,但所有元素仍被隐藏。而是隐藏以pcbid
而不是开头的div div
。
$('[id^=pcbid]').not(name).hide();
$(name).show();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句