jquery选择框(下拉),加载第一个值 [英] jquery select box (dropdown), load first value
问题描述
我可以在用户更改值时加载图像,但我希望查看全部加载当我们看到页面的时候,我知道我可以通过几种不同的方式做到这一点,但是我更喜欢它会在指定值后马上加载。
<$ p $ (函数()){
$(#imagePreview)。empty() ();
$(#imagePreview)。append(< img src = \+ $(#image).val()+\/>);
});
});
< option value =imageall.jpgselected> - 全部 - < / option>
< option value =image1.jpg> image1.jpg< / option>
< option value =image2.jpg> image2.jpg< / option>
< option value =image3.jpg> image3.jpg< / option>
< / select>
< div id =imagePreview>
< / div>
即使您查看Fiddle演示,您也会看到在选择image1等之前它不会加载任何内容。 b
$ b
我希望imageall.jpg能在有人浏览小提琴时正确加载。
谢谢
更改事件在选择元素值发生变化时触发,当然如果您想要,您可以自己触发。
< $ p $
$(document).ready(function(){
$(#image)。change(function(){
$(#imagePreview ).empty();
$(#imagePreview)。append(< img src = \+ $(#image)。val()+\/> );
})。change();
});
I have a dropdown select boy with a few images.
I can get the images to load when the user changes value, but I want the View All to load right when the page is viewed.. I know I can do this a few different ways but I would prefer that it just loads right away since the value is specified.
$(document).ready(function() {
$("#image").change(function() {
$("#imagePreview").empty();
$("#imagePreview").append("<img src=\"" + $("#image").val() + "\" />");
});
});
<select name="image" id="image" class="inputbox" size="1">
<option value="imageall.jpg" selected> - All - </option>
<option value="image1.jpg">image1.jpg</option>
<option value="image2.jpg">image2.jpg</option>
<option value="image3.jpg">image3.jpg</option>
</select>
<div id="imagePreview">
</div>
Even if you view the Fiddle demo, you will see it won't load anything until you select image1 etc.
I want the imageall.jpg to load right when someone views fiddle.
thank you
The change event fires when the select element value changes of course you can fire it yourself if you wanted.
$(document).ready(function() {
$("#image").change(function() {
$("#imagePreview").empty();
$("#imagePreview").append("<img src=\"" + $("#image").val() + "\" />");
}).change();
});
这篇关于jquery选择框(下拉),加载第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!