Js implementation of the select jump function code

  • 2020-03-30 04:11:07
  • OfStack

Js simple implementation of the select jump function: the code is as follows


<!DOCTYPE html> 
<html> 
<head> 
<title></title> 

</head> 
<body> 
<div class="selectBox"> 
<select class="toSlt"> 
<option href="http://jichuang.gongchang.cn/pro-161264/"> All categories of goods </option> 
<option href="http://jichuang.gongchang.cn/"> Ordinary lathe </option> 
<option href="http://jichuang.gongchang.cn/brand/"> Turning lathe </option> 
<option href="http://jichuang.gongchang.cn/"> Ordinary lathe </option> 
<option href="http://jichuang.gongchang.cn/brand/"> Turning lathe </option> 
</select> 
</div> 
<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script> 
<script type="text/javascript"> 

$(function(){ 
var $body = $('body'); 
$body.on('change', 'select:has(option[href])', function(e) { 
var _this = $(this), 
_href = _this.find('option:selected').attr('href');//Gets the address to jump to
location.href = _href; // jump  
}) 
}) 

</script> 
</body> 
</html> 

Related articles: