根据选择框值更改文本 [英] Change text based on select box value
问题描述
完全公开:我对javascript不好.
Full Disclosure: I am bad at javascript.
我正在尝试编写一些内容,使其具有选择框的值(在这种情况下,它包含用户可以选择的主题列表),并将其与包含所有允许的主题的数组进行比较,并显示一个预览指向用户的链接.
I'm trying to write something that takes the value of a select box (in this case, it contains a list of themes the user can choose from), compares it against an array containing all the themes allowed, and display a preview link to the user.
下面是一些选择代码.
包含预览链接的我的阵列":
My Array containing the preview links:
var themePreview = [];
themePreview[0] = ' <a href="http://www.trafficgettingblogs.com/?preview=1&template=arclite&stylesheet=arclite&TB_iframe=true&width=1000&height=700" class="thickbox thickbox-preview">Preview Arclite</a>';
themePreview[1] = ' <a href="http://www.trafficgettingblogs.com/?preview=1&template=arras&stylesheet=arras&TB_iframe=true&width=1000&height=700" class="thickbox thickbox-preview">Preview Arras</a>';
themePreview[2] = ' <a href="http://www.trafficgettingblogs.com/?preview=1&template=carrington-blog&stylesheet=carrington-blog&TB_iframe=true&width=1000&height=700" class="thickbox thickbox-preview">Preview Carrington Blog</a>';
我的jQuery试图获取选择框值并显示预览链接:
My jQuery attempting to get the select box value and display a preview link:
$('select #selectedTheme').change(function() {
//document.write('test'); // Try to see if I'm selecting what I need.
$('#previewTheme').value() = themePreview[$('#selectedTheme option:selected').value()];
});
选择框的ID为selectedTheme
.
我没有收到任何错误,但似乎没有选择选择框.
I'm not getting any errors, but I don't seem to be selecting the select box.
我确信这是一个非常简单的问题.我正在尝试提高我的JavaScript技能.似乎没有成功.
I am sure this is a very simple problem. I'm trying to improve my javascript skills. Rather unsuccessfully, it seems.
推荐答案
代码中的赋值没有任何作用.
The assignment in your code doesn't do anything.
这应该有效:
$('#previewTheme').html( themePreview[$('#selectedTheme option:selected').value()] );
即html()
返回元素的当前内容,html(x)
将其替换为x
.
i.e. html()
returns the current content of an element, html(x)
replaces it with x
.
这篇关于根据选择框值更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!