function SelectDistrict(argument)
{
var sel=document.getElementById("city");
sel.style.display = '';
sel.options.length = 0;
sel.options.add(new Option('Please select a location',''));
var i=1;
var tempInt=parseInt(argument);
if (tempInt%10000==0)
{
var place1=document.getElementById('place1');
place1.innerHTML =county[tempInt];
}
sel.options.add(new Option('all',tempInt));
$('#inputcity').hide();
while (i<=52)
{
tempInt+=100;
if (county[tempInt]==undefined)
{
break;
}
else {
op_cir = new Option(county[tempInt], tempInt);
sel.options.add(op_cir);
}
i++;
}
}
-5
A
Répondre
2
Vous pouvez faire quelque chose comme ceci:
function SelectDistrict(argument)
{
var sel = $('#city'); // Store the jQuery object to save time
sel.hide().empty().append('<option>Please select a location.</option');
var i = 1;
var tempInt = argument;
if (tempInt % 10000 == 0)
{
$('#place1').html(county[tempInt]);
}
sel.append('<option value="'+tempInt+'">all</option>');
$('#inputcity').hide();
var optionsValue = ''; // Appending strings to each other is faster than modifying the DOM
tempInt += 100;
while ((i <= 52) && (county[tempInt] != undefined)) // Just put the condition here instead of breaking the loop
{
optionsValue += "<option value='" + tempInt + "'>" + county[tempInt] + "</option>";
tempInt += 100;
i++;
}
sel.append(optionsValue);
}
J'espère que cela fonctionne pour vous!
0
vous devez remplacer chaque document.getElementById() par $ ("# elementid") comme $ ("# city");
et place1.innerHTML = comté [tempInt]; par $ ("# place1"). text (comté [tempInt]);
0
Vous pouvez changer la boucle while pour:
$.each(county, function(i, itm) {
optionsValue += "<option value='" + i + "'>" + itm + "</option>";
})
Questions connexes
- 1. Comment réécrire ce code jQuery en utilisant Mootools?
- 2. comment réécrire ceci ce javascript en ligne avec jquery?
- 3. Comment faire ce javascript en utilisant jQuery?
- 4. Comment réécrire ce jQuery plus efficacement?
- 5. Comment réécrire cette fonction javascript avec jQuery?
- 6. Comment écrire ce code en utilisant SubSonic?
- 7. comment puis-je changer ce code jquery en javascript pur?
- 8. Comment améliorer ce code en utilisant $ (this) dans jQuery?
- 9. Comment résoudre ce en utilisant jQuery
- 10. Puis-je réécrire une fonction Javascript en utilisant Excel VBA?
- 11. Comment réécrire des URL en utilisant htaccess?
- 12. Comment réécrire des URL en utilisant htaccess?
- 13. Comment réécrire ce javascript qui reçoit un objet de requête comme JQuery
- 14. Où mettre tout ce code JavaScript jQuery?
- 15. Comment réécrire ce bloc eval
- 16. Comment réécrire la requête en utilisant CTE
- 17. Comment puis-je réécrire ce code pour améliorer sa clarté?
- 18. Comment traduire ce pur javascript en jQuery?
- 19. Comment convertir ce javascript en jquery?
- 20. Comment optimiser ce code javascript?
- 21. Comment est-ce que je peux rendre ce vieux code JavaScript/ASP classique (propre) non intrusif, en utilisant JQuery?
- 22. Comment refactoriser ce code jQuery?
- 23. Comment réécrire .php en .html en utilisant les règles .htaccess?
- 24. Comment réécrire le code powershell dans bash
- 25. Comment mettre en surbrillance div en utilisant javascript ou jquery
- 26. Effacer gridview en utilisant javascript/jquery
- 27. réécrire l'adresse url en utilisant vb.net
- 28. en utilisant javascript avec l'aide de jquery
- 29. Comment réécrire un nom de fichier dans le navigateur en utilisant un httphandler - est-ce possible?
- 30. zoom d'image en utilisant javascript ou jquery