当前位置:编程学习 > C#/ASP.NET >>

js隐藏域传值问题,谢谢!

用javascript获得数据后想往后台传数,然后数据操作存入数据库。可是在网上找了半天也没看懂!把代码贴出来大家帮我看看!主要是想把得到的位置数值传到后台!能帮贴出代码最好!
<script language="javascript"><!--
var photoTag = {
show: function(left,top,width, height, show_resize_square) {
$('#select-area-box').css({'left':left - 7, 'top':top - 7})
$('#select-area-box').width(width + 4).height(height + 4).show();
$('#select-area').width(width).height(height);
if(show_resize_square) $('#select-area-box span').show();
else $('#select-area-box span').hide();
},
hide: function() {$('#select-area-box').hide(); },
add:function(tag_name, left, top, width, height) {
var json = {id:Math.floor(Math.random() * 10000)};
//$.getJSON('add_tag.php', {'name':tag_name,'left':left,'top':top,'width':width,'height':height}, function(json) {
//reflesh tag list
// if(json.message) alert(json.message);
// if(json.error == 0) {
var args = left+','+top+','+width+','+height;
var li = '<li>,';
li += '<span onmouseover="photoTag.show('+args+');" ';
li += 'onmouseout="photoTag.hide();">'+tag_name+'</span>';
li += '(<a href="javascript:;" mce_href="javascript:;" onclick="photoTag.remove('+json.id+',this.parentNode);" ';
li += 'onmouseover="photoTag.show('+args+');" onmouseout="photoTag.hide();">删除</a>)';
li += '</li>';
$('#tag-list').append(li);
// }
//});
},
remove: function(id, li) {
//$.getJSON('remove_tag.php', {'tag_id':id}, function(json) {
//reflesh tag list
// if(json.message) alert(json.message);
// if(json.error == 0) 
li.parentNode.removeChild(li);
//});
}
};
 
$(function(){
var is_started = false;
// 选区左上角,和高宽
var info = {'left':0,'top':0,'width':0,'height':0};
var origin = {x:$('#enclose-wrapper').offset().left + (parseInt($('#enclose-wrapper').css('border-left-width'))||0),
  y:$('#enclose-wrapper').offset().top  + (parseInt($('#enclose-wrapper').css('border-top-width'))||0)};
var dnr = new DragResize($('#select-area-box')[0], {
minWidth:20,
minHeight:20,
bound:{left:0,top:0,right:9999,bottom:9999},
callback:function(i) {
// 7为左(上)边两个边框的宽度的和, 4为左右(上下)篮色边框宽度的和
info= {'left':i.left + 7,'top':i.top + 7,'width':i.width - 4,'height':i.height - 4};
$('#select-area').width(info.width).height(info.height);
// 将添加标签的表单定位在选区的右边
$('#form-add-tag').css({'left':i.left + i.width + 10, 'top':i.top});
}
});
// 拖动选区
$('#select-area').mousedown(function(e){
dnr.drag(e);
});
// 调整选区大小
$('#select-area-box span').mousedown(function(e){
dnr.resize(e, this.className.replace('-resize', ''));
});
// 在图片上点击一下,开始获取选区
$('#photo').mousedown(function(e){
if(is_started) return;
is_started = true;
var left = e.pageX - origin.x - 50 - 7;
var top  = e.pageY - origin.y - 50 - 7 ;
 
info= {'left':left + 7,'top':top + 7,'width':100,'height':100};
photoTag.show(info.left, info.top, info.width, info.height, true);
$('#form-add-tag').show().css({'left':left + 100 + 4 + 10, 'top':top});
});
// 鼠标进入图片内时,显示选区
$('#photo').bind('mouseenter',function(e){
if(!is_started) return;
photoTag.show(info.left, info.top, info.width, info.height, true);
});
 
// 确定添加一个标签,或取消
$('#btn-add-tag, #btn-cancel').click(function(e){
if(this.id == 'btn-cancel') {
$('#form-add-tag, #select-area-box').hide();
is_started = false;
return false;
}
if(!$('#tag-name').val()) {
alert('标签名不能为空!');
return false;
}
// 添加标签
photoTag.add($('#tag-name,').val(), info.left, info.top, info.width, info.height);
$('#form-add-tag, #select-area-box').hide();
is_started = false;
         return false;
 
});
photoTag.hide();
 
});
// --></script>
--------------------编程问答--------------------

 <asp:HiddenField ID="HidId" runat="server" />


document.getElementById("HidId").value = "用javascript获得的数据";  
--------------------编程问答--------------------
引用 1 楼 tan598121925 的回复:

 <asp:HiddenField ID="HidId" runat="server" />


document.getElementById("HidId").value = "用javascript获得的数据";  

value的值是否可以是多个数值比如
document.getElementById("HidId").value = info.left, info.top, info.width, info.height";  


还有 后台直接用HidId.value,数值是以什么样的形式存放?  --------------------编程问答-------------------- 多个你就拼接起来,什么形式看你怎样拼接了 --------------------编程问答--------------------  <asp:HiddenField ID="HidId" runat="server" />

var strL="LLL";
var strW="WWW";
var strH="HHH";
var strT="TTT";

document.getElementById("<%=HidId.ClientID%>").value = strL+":"+strW+":"+strH+":"+strT; --------------------编程问答--------------------
引用 4 楼 happytonice 的回复:
 <asp:HiddenField ID="HidId" runat="server" />

var strL="LLL";
var strW="WWW";
var strH="HHH";
var strT="TTT";

document.getElementById("<%=HidId.ClientID%>").value = strL+":"+strW+":"+strH+":"+strT;


为什么后台取不到值
var left="info.left";
var top="info.top";
var width="info.width";
var height="info.height";
document.getElementById("HidId").value = left+";" +top+";" +width+";" +height;
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,