简体   繁体   English

无法将新值分配给我的自动填充框

[英]Can't assign a new value to my autocomplete box

I've created a search page that can be toggled between french and english. 我创建了一个搜索页面,可以在法语和英语之间切换。 So when the user searches a record and toggles to french it displays the same record they were viewing on the english page. 因此,当用户搜索记录并切换到法语时,它会在英语页面上显示与他们查看的记录相同的记录。

What I want to do is display the record name in the search box when the page is toggled.I assumed it was as simple as doing a $('#inputID').val(record); 我想做的是在切换页面时在搜索框中显示记录名称。我认为这和执行$('#inputID')。val(record)一样简单。 but it doesn't seem to be working. 但它似乎不起作用。 I've alerted the record name and it works fine, so I'm stumped. 我已经提醒了记录名称,并且它可以正常工作,所以我很困惑。 All the scripts are linked correctly as well so that's not the problem. 所有脚本也都正确链接,所以这不是问题。

Autocomplete Box Code 自动完成箱码

<div id="ui-widgit">
  <label for="searchParams">
  <h1>Search All Programs (By Screen Number or By Error Code):</h1>
  </label>
  <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" />
  <input type="button" value="Search" name="searchBtn" class="btn_Design" onclick="showSearch(inputID.value)"/>
</div>

Try to change the value of inputID with this 尝试以此更改inputID的值

$('#inputID').val(recordToggle);

also have tried this: 也尝试过这个:

$('#inputID input').val(recordToggle);

It is hard to tell with your presented markup but I am assuming you are trying to change the value of $('#inputID') after the page refreshed. 很难用您提供的标记来区分,但是我假设您正在刷新页面后尝试更改$('#inputID')的值。 It is important where you put this code. 放置此代码的位置很重要。 If it is placed before <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> 如果放在<input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> you will not return anything with $('#inputID') so you will change the value of nothing to your text. <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" />您不会使用$('#inputID')返回任何内容,因此您将不会更改文本的值。 It will give no error. 它不会出错。 To fix this you can use: 要解决此问题,您可以使用:

$( document ).ready(function(){
  $('#inputID').val(recordToggle);
});

Be sure to read about jQuery's ready function because load may be the better choice. 请务必阅读有关jQuery的ready函数的信息,因为加载可能是更好的选择。

If this doesn't fix your problem let me know. 如果这不能解决您的问题,请告诉我。 I will update my answer. 我将更新我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM