我正在尝试根据使用 jQuery 的单选按钮选择来更改一些文本,但我似乎无法让它工作。这是我的代码:
HTML
<input type="radio" name="finish_id" id="1" value="1" checked />
<label for="1" id="veteran"></label>
<input type="radio" name="finish_id" id="2" value="2" />
<label for="2" id="elite"></label>
<input type="radio" name="finish_id" id="3" value="3" />
<label for="3" id="legendary"></label>
<span id="finish_name"></span>
JS
// Set variables
var finish[] = "something";
var finish[] = "something else";
var finish[] = "another thing";
// Change finish name based on radio selection
$(document).ready(function() {
$("input[name='finish_id']").change(function() {
$('#finish_name').text( finish[$(this).val()] );
}).change();
});
我可能与数组编号相差甚远$(this).val()
,我不知道您是否可以那样选择它,但即使我将其设置为$('#finish_name').text( finish[1] );
我也会收到unexpected token [
错误消息。如何将数组值用于 .text()?