如何在 Watson Conversation 中使用 Select 选项
How use Select Option in Watson Conversation
我正在尝试将 select 选项标签插入到我的对话中,以使其对用户来说更简单。我这样做了:
并且在 index.js 中:
function selected(){
switch($('#selected option:selected').val()){
case 01:
alert("01");
break;
case 02:
alert("02");
break;
}
};
但它无法识别 selected 选项。我尝试不使用 selected() 函数(仅使用 switch case),但没有用。有人可以帮我吗?非常感谢!
我相信您在高级上下文中的 HTML 有一些您错过的东西。
在 HTML 在 onselect
中键入 :
,但是,要使用 onselect 并调用一个函数,您必须使用 onselect="nameFnction()"
参见 one MDN 中使用此标签的简单示例:
<input type="text" onselect="myFunction()" value="Hello world!">
现在,请参阅 other 示例以根据选择正常工作:
<select>
<option onclick="doSomethingA(this);">A</option>
<option onclick="doSomethingB(this);">B</option>
<option onclick="doSomethingC(this);">C</option>
</select>
并使用 jQuery(您的 ID 是 select 而不是 selected):
$('#select option:selected').val()
我正在尝试将 select 选项标签插入到我的对话中,以使其对用户来说更简单。我这样做了:
并且在 index.js 中:
function selected(){
switch($('#selected option:selected').val()){
case 01:
alert("01");
break;
case 02:
alert("02");
break;
}
};
但它无法识别 selected 选项。我尝试不使用 selected() 函数(仅使用 switch case),但没有用。有人可以帮我吗?非常感谢!
我相信您在高级上下文中的 HTML 有一些您错过的东西。
在 HTML 在 onselect
中键入 :
,但是,要使用 onselect 并调用一个函数,您必须使用 onselect="nameFnction()"
参见 one MDN 中使用此标签的简单示例:
<input type="text" onselect="myFunction()" value="Hello world!">
现在,请参阅 other 示例以根据选择正常工作:
<select>
<option onclick="doSomethingA(this);">A</option>
<option onclick="doSomethingB(this);">B</option>
<option onclick="doSomethingC(this);">C</option>
</select>
并使用 jQuery(您的 ID 是 select 而不是 selected):
$('#select option:selected').val()