我想根据文本输入值更改选择选项。
例如,在输入mydomain.com时,应该会发生这种情况:
我已经编辑了我的这个老问题,以便更清楚。这是我当时的截图,它可能有助于说明问题:
代码示例:
<input type="text" autocomplete="off" id="domain" name="domain">
<select id="extension" name="extension">
<option value=".com">.com</option>
<option value=".com.br">.com.br</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".info">.info</option>
<option value=".biz">.biz</option>
<option value=".tv">.tv</option>
<option value=".name">.name</option>
<option value=".ws">.ws</option>
<option value=".cc">.cc</option>
<option value=".blog.br">.blog.br</option>
<option value=".flog.br">.flog.br</option>
<option value=".vlog.br">.vlog.br</option>
<option value=".wiki.br">.wiki.br</option>
<option value=".adm.br">.adm.br</option>
<option value=".adv.br">.adv.br</option>
<option value=".agr.br">.agr.br</option>
<option value=".am.br">.am.br</option>
<option value=".arq.br">.arq.br</option>
<option value=".art.br">.art.br</option>
<option value=".ato.br">.ato.br</option>
<option value=".bio.br">.bio.br</option>
<option value=".bmd.br">.bmd.br</option>
<option value=".cim.br">.cim.br</option>
<option value=".cng.br">.cng.br</option>
<option value=".cnt.br">.cnt.br</option>
<option value=".coop.br">.coop.br</option>
<option value=".ecn.br">.ecn.br</option>
<option value=".edu.br">.edu.br</option>
<option value=".eng.br">.eng.br</option>
<option value=".esp.br">.esp.br</option>
<option value=".etc.br">.etc.br</option>
<option value=".eti.br">.eti.br</option>
<option value=".far.br">.far.br</option>
<option value=".fm.br">.fm.br</option>
<option value=".fnd.br">.fnd.br</option>
<option value=".fot.br">.fot.br</option>
<option value=".fst.br">.fst.br</option>
<option value=".g12.br">.g12.br</option>
<option value=".ggf.br">.ggf.br</option>
<option value=".gov.br">.gov.br</option>
<option value=".imb.br">.imb.br</option>
<option value=".ind.br">.ind.br</option>
<option value=".inf.br">.inf.br</option>
<option value=".jor.br">.jor.br</option>
<option value=".lel.br">.lel.br</option>
<option value=".mat.br">.mat.br</option>
<option value=".med.br">.med.br</option>
<option value=".mil.br">.mil.br</option>
<option value=".mus.br">.mus.br</option>
<option value=".net.br">.net.br</option>
<option value=".nom.br">.nom.br</option>
<option value=".not.br">.not.br</option>
<option value=".ntr.br">.ntr.br</option>
<option value=".odo.br">.odo.br</option>
<option value=".org.br">.org.br</option>
<option value=".ppg.br">.ppg.br</option>
<option value=".pro.br">.pro.br</option>
<option value=".psc.br">.psc.br</option>
<option value=".psi.br">.psi.br</option>
<option value=".qsl.br">.qsl.br</option>
<option value=".rec.br">.rec.br</option>
<option value=".slg.br">.slg.br</option>
<option value=".srv.br">.srv.br</option>
<option value=".tmp.br">.tmp.br</option>
<option value=".trd.br">.trd.br</option>
<option value=".tur.br">.tur.br</option>
<option value=".tv.br">.tv.br</option>
<option value=".vet.br">.vet.br</option>
<option value=".zlg.br">.zlg.br</option>
</select>
答案 0 :(得分:1)
您可以使用jQuery在用户输入...
时执行此操作$(document).ready(function() {
$('#search').keyup(function() {
//The user has typed something. See what they typed and split it.
var value = $(this).val();
var components = value.split(".");
if(components.length == 2) {
//They have typed a TLD like .com
if($("#extensao option[value='."+ components[1] + "']").length > 0) {
//They have typed an available TLD. Select the dropdown and update the box.
$("#search").val(components[0]);
$("#extensao").val("." + components[1]);
}
} else if (components.length > 2) {
//They have typed a Second level domain like .blog.br
if($("#extensao option[value='."+ components[components.length - 2] + "." + components[components.length - 1] + "']").length > 0) {
//They have typed an available second level domain.
$("#search").val(components[0]);
$("#extensao").val("." + components[components.length - 2] + "." + components[components.length - 1]);
}
}
});
});
不确定这是否是您正在寻找的解决方案(或服务器端)。无论哪种方式,您都需要额外的服务器端验证。
答案 1 :(得分:0)
我有2个想法怎么做