Javascript 如何在不重新修改页面的情况下重新加载SelymeleAF表?
下面是我的HTML和JavaScript代码,我使用百里香叶动态显示表内容。 如您所见,若通知值为1,则“更改”按钮将被禁用,其CSS也将更改。但当它的值为其他值时,用户可以单击该按钮。一旦用户单击按钮,就会调用worksomething()函数。现在我想要的是,如果用户得到了成功响应,而不需要重新加载页面,附加到所选ID的按钮应该被禁用,它的CSS也应该被更改,比如notified的值为1Javascript 如何在不重新修改页面的情况下重新加载SelymeleAF表?,javascript,html,jquery,css,thymeleaf,Javascript,Html,Jquery,Css,Thymeleaf,下面是我的HTML和JavaScript代码,我使用百里香叶动态显示表内容。 如您所见,若通知值为1,则“更改”按钮将被禁用,其CSS也将更改。但当它的值为其他值时,用户可以单击该按钮。一旦用户单击按钮,就会调用worksomething()函数。现在我想要的是,如果用户得到了成功响应,而不需要重新加载页面,附加到所选ID的按钮应该被禁用,它的CSS也应该被更改,比如notified的值为1 函数工作集(orderId){ $.ajax({ url:“/myirl/”+orderId, 键入:
函数工作集(orderId){
$.ajax({
url:“/myirl/”+orderId,
键入:“GET”,
contentType:“应用程序/json”,
数据类型:“JSON”,
成功:功能(响应){
警报(“禁用”);
},
错误:函数(响应){
警报(“工作失败”);
}
});
}
身份证件
行动
改变
最好使用jQuery之类的Javascript库将JS事件与HTML连接起来。因此,它使代码更加清晰
<table class="table" data-table ="all-orders" id="all-orders" role="grid">
<thead>
<tr>
<th>ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr th:each="order : ${orders}">
<td>
<button class="btn btn-link" th:text="${order?.orderId}"></button>
</td>
<td>
<button type="button" class="btn btn-warning btn-md change-btn"
th:disabled="${(order?.notified)} == 1"
th:style="${(order?.notified) == 1 ? 'background-color: red;border-color:red;' : 'background-color: #eea236;border-color:#eea236;'}"
the:attrs="order-id=${order?.orderId}">
Change</button>
</td>
</tr>
</tbody>
</table>
为什么我不能改变CSS。我使用下面的代码$(myButton).css('background-color,red')$css('border-color,red');请检查文档以使用
css()
方法,它需要.css('background-color','red')
谢谢。。。。这是有效的:$(myButton).prop('disabled',true.).css('background-color','red').css('border-color','red');
$(function(){
$(".change-btn").on('click', function(event){
var ordered = $(this).attr('order-id');
var myButton = $(this);
$.ajax({
url : "/myirl/"+ orderId,
type : 'GET',
contentType : "application/json",
dataType : "JSON",
success: function (response) {
alert("Disabled");
$(myButton).prop('disabled', true);
//to remove disabled:
//$(myButton).prop('disabled', false);
},
error: function (response) {
alert("work Failed");
}
});
});
});