[英]How can I save the css changes from jQuery
Hello i changed the div color with javascript using css. 您好,我使用CSS使用javascript更改了div颜色。 I have a div in repeater.
我在转发器中有一个div。 How can i save the changes for ever.
我如何永久保存更改。 Like if color was yellow.
就像颜色是黄色一样。 After even user gets offline and gets online again , the yellow color will shows in the div.
在甚至用户下线并再次上线后,黄色也会在div中显示。 how can i use this with database?
我该如何与数据库一起使用? Im not good at JQuery codes.
我不太擅长JQuery代码。 Cause of that i need your help.thanks.
因为我需要你的帮助。谢谢。
my code which i have to save is : 我要保存的代码是:
$(document).ready(function () {
$(".divsec").on("click", function () {
$(this).css("background", "red");
});
});
my cs code is : 我的CS代码是:
public static void InsertData(string Color)
{
OleDbConnection con = new OleDbConnection(Utility.GetConnection());
con.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO Temsilci(color) values(@color)", con);
cmd.Parameters.Add("color", Color);
cmd.ExecuteNonQuery();
con.Close();
}
and JS code for save color to database is : 用于将颜色保存到数据库的JS代码是:
$(document).ready(function () {
var color = '';
var clicks = 0;
$(".divsec").on("click", function () {
if (clicks == 1) {
$(this).css("background", "red");
}
else if (clicks == 2) {
$(this).css("background", "green");
}
else if (clicks == 3) {
$(this).css("background", "yellow");
}
else {
clicks = 0;
$(this).css("background", "transparent");
}
++clicks;
var x = $(this).css('backgroundColor');
hexc(x);
alert(color);
$.ajax({
url: 'default.aspx/InsertData',
type:'POST',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: "{Color:'" + color + "'}",
success: function () {
alert("Başarıyla kaydedildi");
},
error: function () {
alert("ERROR");
}
});
});
function hexc(colorval) {
var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
delete (parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
color = '#' + parts.join('');
}
});
it works fine but it send error when want to insert in database the COLOR value. 它工作正常,但在要将COLOR值插入数据库时会发送错误。 And even if it perfectly will do it.
即使它完美地做到了。 I want to save the color of every div which user changed.
我想保存用户更改的每个div的颜色。 how can i capture and save all values from repeater?
如何从中继器捕获并保存所有值?
There is no way you can save the change for ever. 您无法永远保存更改。 Having said that , it is also worth mentioning that you can use
localStorage
, but that will also be erased once user clear browser cache and changes saved in one browser will not effect in other browser 话虽如此,值得一提的是您可以使用
localStorage
,但是一旦用户清除了浏览器缓存,并且在一个浏览器中保存的更改将不会在其他浏览器中生效,也会被删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.