我有一个功能,我需要出现在一个jQuery中$(document).ready(function() {}- 我是j't的javascript,但没有真正使用jQuery.我如何jQuerify这个功能?
function populateContext()
{
contextTxtBox = document.getElementById('searchContext');
pathArr = window.location.pathname.split( '/' );
contextTxtBox.value = pathArr[1].toUpperCase();
};
Run Code Online (Sandbox Code Playgroud)
它实际上几乎是相同的,因为我发现唯一值得 jQuerifying(好词)的是 DOM 元素。
function populateContext()
{
var contextTxtBox = $('#searchContext');
var pathArr = window.location.pathname.split('/');
contentTxtBox.val(pathArr[1].toUppercase());
}
$(document).ready(function()
{
populateContext();
});
Run Code Online (Sandbox Code Playgroud)