<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<input type="radio" name="riskLib" value="yjw1">杨军威1<br/>
<input type="radio" name="riskLib" value="yjw2">杨军威2<br/>
<input type="button" id="Btn_riskLib" />
<script type="text/javascript">
$(document).ready(function(){
$("#Btn_riskLib").bind("click",function(){
var id =$(":radio:checked").val();
if(id==null){
alert("请选择一个!");
}else {
alert(id);
}
})
});
</script>
</body>
</html>
任务和联系人是多对多关系,现在由联系人id查询出所有相关的任务
"SELECT t from Task t join t.contacters c where c.id = ?1"
比如:
一个老师教许多学生,一个学生被许多老师教,一个学生有好多书,同一种书被许多同学拥有.
要查询教拥有书"a"的学生的老师!
Hql语句:
SELECT t FROM Teacher t join t.students s join s.books b where b.name = 'a'
解释:t.students s中s并不是集合的意思,而是t的students对象的表别名,join t.students s这个hql,hibernate会翻译成两个表的内连接关系
错误写法:
SELECT t FROM teacher t where t.students.books.name = 'a'
其实道理是很显然的,t.students是一个Set,那么这个Set怎么可能有books这样的属性呢?同理books.name也不对,所以 使用表间连接并给出别名t.students s,此时的对象s才有books属性,所以可以写s.books b,最后使用b.name限制查询b.name = 'a'.
另外一种写法:
SELECT t FROM Teacher t,Student s,Book b where s.id in elements(t.students) and b.id in elements(s.books)
这种方法没有出错!不过这种方式要用子查询!
public Map readXml() {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc;
InputStream stream = this.getClass().getResourceAsStream("/dictionaries.xml");
doc = builder.parse(stream);
Element root = doc.getDocumentElement();
NodeList list = root.getElementsByTagName("dictionary");
Map map = new LinkedHashMap();
ArrayList<String> types = new ArrayList<String>();
for (int i = 0; i < list.getLength(); i++) {
String key = list.item(i).getAttributes().getNamedItem("name").getNodeValue();
String value = list.item(i).getAttributes().getNamedItem("value").getNodeValue();
map.put(key, value);
}
return map;
} catch (Exception ex) {
return null;
}
}
dictionaries.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<dictionaries>
<dictionary name="项目类型" value="project.types" />
<dictionary name="项目状态" value="project.statuses" />
<dictionary name="任务阶段" value="task.stages" />
<dictionary name="任务状态" value="task.statuses" />
<dictionary name="发生几率" value="risk.probability" />
<dictionary name="危险程度" value="risk.harm" />
<dictionary name="风险状态" value="risk.status" />
<dictionary name="预案类别" value="risk.type" />
<dictionary name="合同类型" value="contract.type" />
<dictionary name="合同状态" value="contract.status" />
</dictionaries>
<html>
<body>
<input type="button" value="add row" id="addrow"/>
<table>
<tr>
<td width="20"><input type="checkbox" /><td>
<td>dddddddd</td>
</tr>
</table>
</body>
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
$('input[type="checkbox"]').live('click',function(){//live给新添加的节点添加事件
$(this).parent().parent().remove();
});
$('addrow').mouseover(function(){
$(this).css('color','red');
});
$('addrow').mouseout(function(){
$(this).css('color','red');
});
$('#addrow').click(function(){
var tr = $('<tr>');
var td1 = $('<td>');
td1.attr('width','20');
var input = $('<input>');
input.attr('type','checkbox');
var td2 = $('<td>');
td2.text('aaaa');
td1.append(input);
tr.append(td1);
tr.append(td2);
//$('table').append(tr);
$('tbody tr:first').before(tr);
});
});
</script>
</html>
<html>
<body>
<input type="button" value="add row" id="addrow"/>
<table>
<tr>
<td width="20"><input type="checkbox" /><td>
<td>dddddddd</td>
</tr>
</table>
</body>
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
$(this).parent().parent().remove();
});
$('#addrow').click(function(){
var tr = $('<tr>');
var td1 = $('<td>');
td1.attr('width','20');
var input = $('<input>');
input.attr('type','checkbox');
var td2 = $('<td>');
td2.text('aaaa');
td1.append(input);
tr.append(td1);
tr.append(td2);
$('table').append(tr);
});
});
</script>
</html>
<html>
<head></head>
<body>
<form name="fm1" id="fm1">
name:<input type="text" name="name" id="name1" />
<input type="submit" id="s1"/>
</form>
<form name="fm2" id="fm2">
name:<input type="text" name="name" id="name2" />
<input type="submit" id="s2" />
</form>
<script type="text/javascript">
//var form = document.getElementById('fm2');
//var formarray = document.forms[1];//得到页面中所以表单的数组
//var form = document.forms['fm1'];//根据表单name属性得到数组
var form = document.fm1;//根据表单name属性得到数组
alert(form);
</script>
</body>
</html>
<html>
<head></head>
<body>
<input type="text" id="mytext" />
<span id="myspan"></span>
<script type="text/javascript">
var mytext=document.getElementById('mytext');
var myspan=document.getElementById('myspan');
mytext.onfocus = function(){
myspan.innerHTML = '得到焦点';
}
mytext.onblur = function(){
myspan.innerHTML = '失去焦点';
}
window.onbeforeunload=function(){
var v = mytext.value;
alert(v);
if(v){
return '444';
}
}
</script>
</body>
</html>
<html>
<head></head>
<body>
<div id="div1">1111111111
<div id="div2">2222222222</div>
</div>
<input type="button" id="btn" />
<a href="http://www.baidu.com" id="mya">163</a>
<a href="javascript:;" >普通按钮,不跳转</a>
<script type="text/javascript">
var eventUtil = {
addHandler:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
}else if(element.attachEvent){
element.attachEvent('on'+type,handler);
}else {
element['on'+type]=handler;
}
},
getEvent:function(event){
return event ? event : window.event;
},
getElement: function(e){
if(e.target){
return e.target;
}else {
return e.srcElement;
}
},
preventDefault:function(e){
if(e.preventDefault){
e.preventDefault();
}else {
e.returnValue=false;
}
},
stopPropagation : function(e){
if(e.stopPropagation){
e.stopPropagation();
}else {
e.cancelBubble=true;
}
}
};
function test(event){
var e = eventUtil.getEvent(event);
alert("1="+e);
var element = eventUtil.getElement(e);
element.value = '33333333';
alert("2="+element);
}
var btn = document.getElementById('btn');
eventUtil.addHandler(btn,'click',test);
</script>
</body>
</html>
在非ie中
<html>
<head></head>
<body>
<div id="div1">1111111111
<div id="div2">2222222222</div>
</div>
<input type="button" id="btn" />
<a href="
http://www.baidu.com" id="mya">163</a>
<a href="javascript:;" >普通按钮,不跳转</a>
<script type="text/javascript">
document.getElementById('btn').onclick = function(event){
//在非ie中
alert(event.type);
alert(event.target);
}
document.getElementById('mya').onclick = function(event){
alert(event.cancelable);
if(event.cancelable){
event.preventDefault();//阻止事件的发生
}
}
document.getElementById('btn').onclick = function(event){
//alert(1);
event.stopPropagation();//阻止事件的传播
}
document.body.onclick=function(){
//alert(2);
}
</script>
</body>
</html>
在ie中
<html>
<head></head>
<body>
<div id="div1">1111111111
<div id="div2">2222222222</div>
</div>
<input type="button" id="btn" />
<a href="
http://www.baidu.com" id="mya">163</a>
<a href="javascript:;" >普通按钮,不跳转</a>
<script type="text/javascript">
var event;
function getEvent(){
event=window.event;
}
document.getElementById('btn').onclick = function(event){
getEvent();
alert(event.type);
alert(event.srcElement);//得到目标元素
event.cancelBubble = true;//取消事件冒泡
event.returnValue = false;//取消默认行为
}
//使用下面的方法可以在参数中得到event
document.getElementById('btn').attachEvent('onclick',function(event){
});
</script>
</body>
</html>
<html>
<head></head>
<body>
<div id="div1">1111111111
<div id="div2">2222222222</div>
</div>
<script type="text/javascript">
var EventUtil = {
addHandler:function(element,type,handler){
if(element.addEventListener){
element.addEventListener(type,handler,false);
}else if(element.attachEvent){
element.attachEvent('on'+type,handler);
}else {
element['on'+type]=handler;
}
},
removeHandler:function(element,type,handler){
if(element.addEventListener){
element.removeEventListener(type,handler,false);
}else if(element.attachEvent){
element.detachEvent('on'+type,handler);
}else {
element['on'+type]=null;
}
}
}
function alertid(){
alert(this.id);
}
var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
EventUtil.addHandler(div2,'click',alertid);
//EventUtil.removeHandler(div2,'click',alertid);
//ie
//div1.attachEvent('onclick',alertid);
//div2.attachEvent('onclick',alertid);
//非ie
//div1.addEventListener('click',alertid,true);
//div2.addEventListener('click',alertid,true);
</script>
</body>
</html>