$(".ewm").ready(function(){ var inputBox = document.getElementById("input-box"); inputBox.addEventListener("focus", function() { inputBox.removeAttribute("placeholder"); }); inputBox.addEventListener("blur", function() { inputBox.setAttribute("placeholder", "请扫描料框条码"); }); 换成jquery })
时间: 2023-07-19 07:44:14 浏览: 46
可以将上述代码用 jQuery 重写如下:
```
$(document).ready(function() {
var inputBox = $("#input-box");
inputBox.focus(function() {
inputBox.removeAttr("placeholder");
});
inputBox.blur(function() {
inputBox.attr("placeholder", "请扫描料框条码");
});
});
```
这里使用了 `$(document).ready()` 方法来确保 DOM 加载完成后再执行 JavaScript 代码。然后使用 `$()` 函数来选取 `input-box` 元素,并将其绑定 `focus` 和 `blur` 事件的处理函数,从而实现与原代码相同的功能。
相关问题
$(document).ready(function(){ var ewm=$(".ewm").val(); if(ewm.autofocus != true){ $.ajax({ type: "get", url: "http://localhost:5000/api/Test/str3", dataType: "jsonp", jsonp: "callback", data: "lt=sfdafda", contentType: "application/json; charset=utf-8", success: function(info) { var pjson = eval(info.data); var result = ""; $.each(pjson, function(i, data) { result += "<tr><td>" + data.sn + "</td><td>" + "<input type='checkbox' data-id='" + (data.sn) + "' class='cbitems' style='width:200px; height: 50px;margin:0 auto;display: block;'>" + "</td></tr>"; }); $("#tbl4").append(result); }, error: function(XMLHttpResponse, textStatus, errorThrown) { console.log(XMLHttpResponse, textStatus, errorThrown); }, });输入完成后自动搜索并显示 具体代码
根据你提供的代码,我理解你的需求是在页面加载完成后,自动执行一次ajax请求,将返回结果展示在页面上。可以使用以下代码实现:
```
$(document).ready(function(){
var ewm=$(".ewm").val();
if(ewm.autofocus != true){
// 执行一次ajax请求
$.ajax({
type: "get",
url: "http://localhost:5000/api/Test/str3",
dataType: "jsonp",
jsonp: "callback",
data: "lt=sfdafda",
contentType: "application/json; charset=utf-8",
success: function(info) {
var pjson = eval(info.data);
var result = "";
$.each(pjson, function(i, data) {
result += "<tr><td>" + data.sn + "</td><td>" +
"<input type='checkbox' data-id='" + (data.sn) +
"' class='cbitems' style='width:200px; height: 50px;margin:0 auto;display: block;'>" +
"</td></tr>";
});
$("#tbl4").append(result);
},
error: function(XMLHttpResponse, textStatus, errorThrown) {
console.log(XMLHttpResponse, textStatus, errorThrown);
},
});
}
});
```
上述代码将在页面加载完成后执行一次ajax请求,并将结果展示在id为tbl4的表格中。你可以根据实际需求进行修改和优化。
'numpy.ndarray' object has no attribute 'ewm'
根据提供的引用内容,'numpy.ndarray'对象没有'ewm'属性。这意味着在使用'ewm'方法时出现了错误。可能的原因是您正在尝试在numpy数组上调用'ewm'方法,但该方法不适用于numpy数组。
要解决此问题,您可以尝试以下方法之一:
1. 检查您的代码,确保您正在调用正确的方法并在正确的对象上使用它。
2. 确保您已正确导入所需的库和模块,并且版本兼容。
3. 查看numpy文档或搜索相关资源,以了解如何在numpy中执行您想要的特定操作。
请注意,根据提供的引用内容,我无法提供更具体的解决方案。如果您能提供更多上下文或代码示例,我将能够更好地帮助您解决问题。