js 截取上传图片示例 2

<script type="text/javascript">
$(function(){

$("#returnback").click(function(){
window.location.href = "<%=request.getContextPath() %>/cntportal/cnt_queryPageCntList.action";
});
$("#ftp").click(function(){
$("#bao").hide();
$("#attachFtp").show();
});

$("#http").click(function(){
$("#bao").show();
$("#attachFtp").hide();
});
/**
//验证IP
$("#Ip").blur(function(){
if(required($(this),'FTP服务器地址不能为空')){
var iptext=$(this).val().split(".");
for(var i=0;i<iptext.length;i++){
var ip=iptext[i];
if(isNaN(ip)){
$(this).next().html("<span style='color:red'>FTP服务器地址必须为数字 如 10.42.95.101</span>");
haveError=true;
return;
}else if(ip<0 || ip>255){
$(this).next().html("<span style='color:red'>FTP服务器地址不正确 如 10.42.95.101</span>");
haveError=true;
return true;
}
}
$(this).next().html("<span style='color:black'>请输入FTP服务器地址:如 10.42.95.101</span>");
}
});
//验证端口号
$("#port").blur(function(){
if(required($(this),'FTP端口号不能为空')){
var post=$(this).val();
if(isNaN(post)){
//alert("<s:text name="doc.postIsOnlyNumber"/>");
$(this).next().html("<span style='color:red'>FTP端口号只能为数字 如 21</span>");
haveError=true;
}else{
$(this).next().html("<span style='color:black'>请输入FTP端口号:如 21</span>");
}
}
});
//验证用户名
$("#username").blur(function(){
if(required($(this),'FTP服务器登录账号不能为空')){
$(this).next().html("<span style='color:black'>请输入FTP服务器登录账号</span>");
}
});
//验证密码
$("#pwd").blur(function(){
if(required($(this),'FTP服务器登录密码不能为空')){
$(this).next().html("<span style='color:black'>请输入FTP服务器登录密码</span>");
}
});
//验证路径
$("#path").blur(function(){

if(required($(this),'FTP服务器上文件路径不能为空') && maxLength($(this),500,'上传文件的路径不能大于500个字符')){
//开头符号
var headpath=$(this).val().substring(0,1);
var filename=$(this).val().substring($(this).val().lastIndexOf("/")+1);
if(headpath=="/"){
$(this).next().html("<span style='color:red'>路径开头不需要”/“ 如 path/pathone/pathtwo/file.rar</span>");
haveError=true;
}else if(filename.lastIndexOf(".")==filename.length+1 || filename.lastIndexOf(".")==-1 || filename.lastIndexOf(".")==0){
$(this).next().html("<span style='color:red'>请输入正确格式的路径 如 path/pathone/pathtwo/file.rar</span>");
haveError=true;
}else{
$(this).next().html("<span style='color:black'>请输入FTP服务器上文件路径:如 path/pathone/pathtwo/file.rar</span>");
}
}
});
*/
});

var figure1=0;
var figure2=0;
var figure3=0;
var figure4=0;

var saveImg=0;
function transferHtml(str){
if(null!=str)
{
        if(str.indexOf("&")>-1){
str = str.replace("&", "&amp;");
}
       
if(str.indexOf("<")>-1){
str=str.replace("<", "&lt;");
}

if(str.indexOf(">")>-1){
str=str.replace(">", "&gt;");
}

if(str.indexOf("\"")>-1){
str = str.replace("\"", "&quot;");
}

if(str.indexOf("'")>-1){
  str = str.replace("'", "&#039;");
  }

if(str.indexOf("\n")>-1){

str = str.replace("\n", "<br>");
}
if(str.indexOf("\r")>-1){

str = str.replace("\r", "&nbsp;&nbsp;&nbsp;&nbsp;");
}

if(str.indexOf(" ")>-1){
str = str.replace(" ", "&nbsp;");
}
}
return str;
}

function getLen(str){
var len=0;
if(null!=str&&str!=""){
for(var i=0;i<str.length;i++){
var intCode=str.charCodeAt(i);
//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
if (intCode>=0&&intCode<=127&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
len=len+1;
}else{
len=len+3;
}
}
}
return len;
}

function preview(img, selection) {
    if (!selection.width || !selection.height)
        return;
   
    var scaleX = 88 / selection.width;
    var scaleY = 88 / selection.height;

    var xxx=img.width;
var yyy=img.height;
    $('#preview img').css({
        width: Math.round(scaleX * 200 ),
        height: Math.round(scaleY * yyy * xxx/200),
        marginLeft: -Math.round(scaleX * selection.x1),
        marginTop: -Math.round(scaleY * selection.y1)
    });

    $('#x').val(selection.x1);
    $('#y').val(selection.y1);
    $('#width').val(selection.width);
    $('#height').val(selection.height);   
}

$(function () {
    $('#photo').imgAreaSelect({
    aspectRatio: '1:1',
    handles: true,
        fadeSpeed: 200,
        onSelectChange: preview
       });
});

//验证用户选择附件是否带有后缀名存在
function copyRightOnChange(){
var typetest=/\.gif$|\.jpg$|\.png$|\.doc$|\.docx$|\.txt$/i;
var spanId = document.getElementById("spanCopy");
var fjsize=document.getElementById("copyrightfile").value;
if(null!=fjsize&&fjsize.length>0){
var index1 = fjsize.lastIndexOf("\\");
var fjname=fjsize.substr(index1+1);
var index2 = fjname.lastIndexOf(".");
if(index2>0&&index2<fjname.length){
var type=fjsize.substr(index2+1);
if(!typetest.test(type) && type!=null && type!=""){
alert("版本附件格式不正确,只能上传以下文件格式:gif,jpg,png,doc,docx,txt");
spanId.innerHTML="";
spanId.innerHTML="<input type=\"file\" name=\"copyrightfile\" onchange=\"copyRightOnChange();\"id=\"copyrightfile\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
return false;
}

}else{
alert("版本附件格式不正确,请重新选择");
spanId.innerHTML="";
spanId.innerHTML="<input type=\"file\" name=\"copyrightfile\" onchange=\"copyRightOnChange();\"id=\"copyrightfile\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
return false;
}
}

//自测情况表和版权文件大小验证
   $("#form1").attr("action","<%=request.getContextPath() %>/cntportal/com_checkFileSize.action");
$("#form1").submit();
}

//验证自测表格式是否带有后缀
function testFileOnChange(){
var typetest=/\.gif$|\.jpg$|\.png$|\.doc$|\.docx$|\.txt$/i;
var spanTest = document.getElementById("spanTest");
var testfile=document.getElementById("testfile").value;
if(null!=testfile&&testfile.length>0){

var index1 = testfile.lastIndexOf("\\");
var fjname=testfile.substr(index1+1);
var index2 = fjname.lastIndexOf(".");
if(index2>0&&index2<fjname.length){
var type=testfile.substr(index2+1);
if(!typetest.test(type) && type!=null && type!=""){
alert("用户自测情况表格式不正确,只能上传以下文件格式:gif,jpg,png,doc,docx,txt");
spanTest.innserHTML="";
spanTest.innerHTML = "<input type=\"file\" name=\"testfile\" id=\"testfile\" onchange=\"testFileOnChange();\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
return false;
}
}else{
alert("用户自测情况表格式不正确,请重新选择");
spanTest.innserHTML="";
spanTest.innerHTML = "<input type=\"file\" name=\"testfile\" id=\"testfile\" onchange=\"testFileOnChange();\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
return false;
}

//自测情况表和版权文件大小验证
   $("#form1").attr("action","<%=request.getContextPath() %>/cntportal/com_checkFileSize.action");
$("#form1").submit();
}
}
//软件包验证
function softOnChange(){
    var app_namejy = document.getElementById("softfile1").value;
    var spanSoft = document.getElementById("spanSoft");
    if(null != app_namejy && ""!=app_namejy){
    //判断上传软件包附件名 是否带后缀
var index1 = app_namejy.lastIndexOf("\\");
var namejy = app_namejy.substr(index1+1);
var index2 =  namejy.lastIndexOf(".");
if(index2 <=0 || index2 >= namejy.length){
alert("软件包文件名格式不正确,请重新选择");
spanSoft.innerHTML = "";
spanSoft.innerHTML ="<input type=\"file\" name=\"softfile\" id=\"softfile1\" onchange=\"softOnChange();\" onmousedown=\"this.oncontextmenu = function(){return false;}\" onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />";
return false;
}
}
}

//图标原图和预览图验证
function onUploadImg(pic){
var picName=$("#"+pic).val();
if(null!=picName&&""!=picName){
picName=picName.substr(picName.lastIndexOf("\\")+1);
if(pic=="image"){
var jy=/^[0-9a-zA-Z_.]+$/;
if(!jy.test(picName)){
alert("图标名称只能包含字母数字下划线和英文句点");
$('#upload').empty();
   $('#upload').append("<input type='file' class=\"width360p input2 marginbottom5p\" name='image'id='image' onchange=\"onUploadImg('image')\" onmousedown=\"this.oncontextmenu = function(){return false;}\"  /> <br/> 图标尺寸大于88*88,文件大小0—2M,格式仅限 jpg png格式,截图用于手机客户端、web门户展示作品");
return false;
}else if( !picName.match( /.jpg|.png/i ) ){
    alert('图片格式无效!');
    $('#upload').empty();
   $('#upload').append("<input type='file' class=\"width360p input2 marginbottom5p\" name='image' id='image'  onchange=\"onUploadImg('image')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" /> <br/> 图标尺寸大于88*88,文件大小0—2M,格式仅限 jpg png格式,截图用于手机客户端、web门户展示作品");
return false;
}

}else if(pic=='pic1'){
if( !picName.match( /.jpg|.gif|.png/i ) ){
    alert('图片格式无效!');
runpicremove('pic1');
return false;
}
}else if(pic=='pic2'){
if( !picName.match( /.jpg|.gif|.png/i ) ){
    alert('图片格式无效!');
runpicremove('pic2');
return false;
}
}else if(pic=='pic3'){
if( !picName.match( /.jpg|.gif|.png/i ) ){
    alert('图片格式无效!');
runpicremove('pic3');
return false;
}
}else if(pic=='pic4'){
if( !picName.match( /.jpg|.gif|.png/i ) ){
    alert('图片格式无效!');
runpicremove('pic4');
return false;
}
}

// 校验价格
var double = /^[-\+]?\d+(\d+)?$/ ;
var require = /.+/ ; // 必填
var fee = $('#fee').val();
if (require.test(fee)) {
if(!double.test(fee)){
alert("请输入正确价格")
document.getElementById("fee").focus();
$('#upload').empty();
   $('#upload').append("<input type='file' class=\"width360p input2 marginbottom5p\" name='image' id='image'  onchange=\"onUploadImg('image')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" /> <br/> 图标尺寸大于88*88,文件大小0—2M,格式仅限 jpg png格式,截图用于手机客户端、web门户展示作品");
return false;
}
}

$("#pic").val(pic);
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/com_checkImg.action");
$("#form1").submit();
}

}

//验证图标原图和预览图错误返回方法
window.imageCheckFail = function(error,picid){
alert(error);
if(picid=='pic1'){
runpicremove('pic1');
}else if(picid=='pic2'){
runpicremove('pic2');
}else if(picid=='pic3'){
runpicremove('pic3');
}else if(picid=='pic4'){
runpicremove('pic4');
}else if(picid=='image'){
$('#upload').empty();
   $('#upload').append("<input type=\"file\" name=\"image\" class=\"width360p input2 marginbottom5p\" "+
   "id=\"image\" onchange=\"onUploadImg('image')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" /> <br/>  图标尺寸大于88*88,文件大小0—2M,格式仅限 jpg png格式,截图用于手机客户端、web门户展示作品");
}
$('#cutImage').attr("disabled","");
}


//验证图标原图和预览图正确返回方法
window.imageCheckSuccess = function(name,picid,imageNO){
if(picid=='pic1'){
figure1=1;
var pic=document.getElementById('pic1');
onUploadImgChange(pic, 'p1', 'preview_fake1', 'preview_size_fake1','example1_div');
}else if(picid=='pic2'){
figure2=1;
var pic=document.getElementById('pic2');
onUploadImgChange(pic, 'p2', 'preview_fake2', 'preview_size_fake2','example2_div');
}else if(picid=='pic3'){
figure3=1;
var pic=document.getElementById('pic3');
onUploadImgChange(pic, 'p3', 'preview_fake3', 'preview_size_fake3','example3_div');
}else if(picid=='pic4'){
figure4=1;
var pic=document.getElementById('pic4');
onUploadImgChange(pic, 'p4', 'preview_fake4', 'preview_size_fake4','example4_div');
}else if(picid=='image'){
var picName=$("#"+picid).val();
if(null!=picName&&""!=picName){
picName=picName.substr(picName.lastIndexOf("\\")+1);
$("#imageNamecopy").val(picName);
$("#imageName").val(picName);
}
$("#photo").attr("src","");
$("#photo").attr("src","<%=request.getContextPath()%>/filepath/temp/${loginUserInfo.userid}/"+name+"?r="+imageNO);
$("#preview img").attr("src","<%=request.getContextPath()%>/filepath/temp/${loginUserInfo.userid}/"+name+"?r="+imageNO);
}else if(picid=='cutImage'){
saveImg=1;
$('#saveImage').empty();
$('#saveImage').append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src='<%=request.getContextPath()%>/filepath/temp/${loginUserInfo.userid}/"+imageNO+"small.png' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
$('#saveImage').append("&nbsp;&nbsp;&nbsp;&nbsp;<image src='<%=request.getContextPath()%>/filepath/temp/${loginUserInfo.userid}/"+imageNO+"middle.png' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
$('#saveImage').append("&nbsp;&nbsp;&nbsp;&nbsp;<image src='<%=request.getContextPath()%>/filepath/temp/${loginUserInfo.userid}/"+imageNO+"large.png' />");
$('#cutImage').attr("disabled","");
}
}

//软件包大小验证
function onUploadSoftfile(pic){

if(pic!=null&&pic!=""){
$("#pic").val(pic);
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/com_checkImg.action");
$("#form1").submit();
}

}

//软件包大小验证错误返回方法
window.softfileCheckFail = function(error,softfile){
alert(error);
if(softfile=='softfile'){
var spanSoft = document.getElementById("spanSoft");
   
spanSoft.innerHTML = "";
spanSoft.innerHTML ="<input type=\"file\" name=\"softfile\" id=\"softfile1\" onchange=\"softOnChange();\" onmousedown=\"this.oncontextmenu = function(){return false;}\" onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />";
}
//如果是附件大小验证错误
if(softfile=='copyrightfile'){
var spanId = document.getElementById("spanCopy");
spanId.innerHTML="";
spanId.innerHTML="<input type=\"file\" name=\"copyrightfile\" onchange=\"copyRightOnChange();\"id=\"copyrightfile\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
// $("#spanCopy").focus();
return false;
}
//如果是自测情况表大小验证错误
if(softfile=='testfile'){
var spanTest = document.getElementById("spanTest");
spanTest.innserHTML="";
spanTest.innerHTML = "<input type=\"file\" name=\"testfile\" id=\"testfile\" onchange=\"testFileOnChange();\" onkeydown=\"return false;\" onmousedown=\"this.oncontextmenu = function(){return false;}\" class=\"width360p input2 marginbottom5p\" size=\"40\" value=\"\" />";
//$("#spanTest").focus();
return false;
}

$("#btn_add").attr("disabled","");
}


//软件包大小验证正确返回方法
window.softfileCheckSuccess = function(softfile){

if(softfile=='softfile'){
window.add();
}
$("#btn_add").attr("disabled","");
$("#div_softname").html("");
}


//保存截图
$("#cutImage").bind("click",function(){
var imageNamecopy=$("#imageNamecopy").val();
if(null!=imageNamecopy&&""!=imageNamecopy){

if(null==$('#width').val()||$('#width').val()==''){
alert("请选择截图区域");
return false;
}

$('#cutImage').attr("disabled","true");
setTimeout("$('#cutImage').attr('disabled','');",3000);
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/com_cutImage.action");
$("#form1").submit();

}else{
alert("请先选择图片");
}
});

//弹出常用标签
function testMessageBox(event)
{
var objPos = mousePosition(event);
var messContent=document.getElementById("keyword").innerHTML;
var messBottom="<input type='button' value='确定' onclick='selectKeyWord()'>";
showMessageBox('常用标签列表',messContent,messBottom,objPos,350);
}


//设置select的可见状态
function setSelectState(state)
{
var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++)
{
objl[i].style.visibility=state;
}
}
function mousePosition(ev)
{
if(ev.pageX||ev.pageY)
{
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
};

}
var isIe=(document.all)?true:false;
var bWidth;
var bHeight;
var back=document.createElement("div");
back.id="back";
var styleStr;

var mesW=document.createElement("div");
mesW.id="mesWindow";
mesW.className="mesWindow";

//弹出方法
function showMessageBox(wTitle,content,messBottom,pos,wWidth)
{
closeWindow();

if(isIe){
setSelectState('hidden');
}
bWidth=parseInt(document.documentElement.scrollWidth);
bHeight=parseInt(document.documentElement.scrollHeight);


styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
back.style.cssText=styleStr;
document.body.appendChild(back);
showBackground(back,30);

mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom' align='center' >"+messBottom+"</div>";
styleStr="left:"+(((pos.x-wWidth)>0)?(pos.x-wWidth):pos.x)+"px;top:"+(pos.y)+"px;position:absolute;width:"+wWidth+"px;";
mesW.style.cssText=styleStr;
document.body.appendChild(mesW);
}
//让背景渐渐变暗
function showBackground(obj,endInt)
{
if(isIe){
obj.filters.alpha.opacity+=1;
if(obj.filters.alpha.opacity<endInt){
setTimeout(function(){showBackground(obj,endInt)},5);
}
}else{
var al=parseFloat(obj.style.opacity);al+=0.01;
obj.style.opacity=al;
if(al<(endInt/100)){
setTimeout(function(){
showBackground(obj,endInt)},5);
}
}
}
//关闭窗口
function closeWindow()
{
if(document.getElementById('back')!=null)
{
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null)
{
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
if(isIe){
setSelectState('');
}
}

//选择标签

function selectKeyWord()
{

var keyword=$("#keywords2").val();
var keyword1 = keyword;

keyword1=trim(keyword1);
keyword1=keyword1.replace(",",",");
var keywords=keyword1.split(",");
     
    $(".keyword").each(function (i) {
if($(this).attr("checked")){

var count=keywords.length;
for(var i=0;i<keywords.length;i++){
if(keywords[i]==$(this).val()){
break;
}

if(i==keywords.length-1){
count++;
if(null == keyword || ""== keyword ){
if(count>6){
break;
}
}else{
if(count>5){
break;
}
}
keywords[i+1]=$(this).val();
if(keyword1.length>0){
keyword1=keyword1+",";
}
keyword1=keyword1+$(this).val();
}
}
}
});
$("#keywords2").val(keyword1);
closeWindow();
}

//弹出保存自定义终端组框
$("#various2").bind("click",function(){
if($("#middlemodel option").length<1){
alert("请先选择终端");
return false;
}

var objPos = mousePosition(event);
var messContent2="<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入终端组名称:&nbsp;&nbsp;<input type='text' id='userTerminalgroup'/><div>";
var messBottom2=document.getElementById("savTerminalGroupDiv").innerHTML;
showMessageBox('自定义终端组',messContent2,messBottom2,objPos,350);

});


//保存自定义终端组
function savTerminalgroup()
{
var terminalgrpname=$("#userTerminalgroup").val();
terminalgrpname=trim(terminalgrpname);
if(terminalgrpname==""||terminalgrpname==null||terminalgrpname.length<1){
alert("终端名称不能为空");
return false;
}

if(terminalgrpname.indexOf("<")>-1||terminalgrpname.indexOf(">")>-1||terminalgrpname.indexOf("\'")>-1||terminalgrpname.indexOf("\"")>-1){
alert(" 自定义终端组名称不能包含“<”,“>”,“\'”,“\"”");
return false;
}

var modles = "";
$("#middlemodel option").each(function (){
  modles = modles + $(this).val() + ",";
  });
 
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_savUserTerminalgroup.action",
   data: "modles="+modles+"&terminalgrpname="+terminalgrpname,
   dataType: "json",
   success: function(data){
   $("#zdzsq").attr("checked","");
   $("#userModelGroup").empty();
   $("<option  value=''>--请选择--</option>").appendTo("#userModelGroup");
   if(data!=null&&""!=data){
   $.each(data,function(index,content){
   $("<option value='"+content['terminalgrpidx']+"'>"+content['terminalgrpname']+"</option>").appendTo("#userModelGroup");
  });
   }
   }
});

closeWindow();
}


function trim(str)
{
str = str.replace( /^\s*/, "");
str = str.replace( /\s*$/, "");
str = str.replace( /^[" "|" "]*/, "");
str = str.replace( /[" "|" "]*$/, "");
return str;
}
(function($){
            var remainEvent = function(event){
                    var multiple = 3;
                    var chineseLength = 0;
var txt = $(this).val();
/**
                    var cArr = txt.match(/[^\x00-\xff]/ig);
                    if (cArr != null)
                    {
                    chineseLength = multiple * cArr.length - cArr.length;
                    }
var count = txt.length + chineseLength;
**/
var count = getLen(txt);

var remain = 2000 - count;
if(remain <= 0)
{
  //粘贴处理
var len=0;
var chang=0;
  for(var i=0;i<txt.length;i++){
  char = txt.charCodeAt(i);
  //如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
    if (char>=0&&char<=127&&char!=34&&char!=38&&char!=39&&char!=47&&char!=60&&char!=62&&char!=92){
     len = len + 1;
  } else {
     len = len + 3;
  }
 
if(len<=2000){
  chang=chang+1;
}
}
txt = txt.substr(0,chang);
var id=this.id
document.getElementById(id).value=txt;
event.preventDefault();
remain=0;
}
$(this).next().text("您还可以输入"+remain+" 个字符!") ;

                };
            var taBlurEvent = function(event){
var txt = $(this).val();
txt = txt.replace( /^\s+|\s+$/g, "" );
if(txt.length < 1) {
var id = $(this).attr("id");
}
else {
remainEvent.call(this,event);
}
            };

            $(function(){
                      
$("#keywords2, #yysm, #guidance, #strategy, #copyright, #remarks").bind("focus", function(){
var txt = $(this).val();
if(txt.indexOf("请在这输入") != -1) {//判断是否进行清空,根据实际情况进行改变
$(this).val("");
}
if(txt.indexOf("如,aa,aa") != -1) {
$(this).val("");
}
$(this).css("color", "#000000");
                   
                });

$("#yysm, #guidance, #strategy, #copyright, #remarks").bind("blur", taBlurEvent).bind("keyup", remainEvent).bind("keypress", remainEvent);
            })
           
           
           
            //点击保存草稿一
$("#saveTemp1").bind("click",function(){
$("#saveORnext").val("saveTemp");
var chineseLength = 0;
          var multiple = 3;
var require = /.+/ ; // 必填
   // 校验名称
var appname = $('#appName').val();
var appnames=appname.split(" ");
appnamejy="";
for(var i=0;i<appnames.length;i++){
appnamejy=appnamejy+appnames[i];
}
if(!require.test(appname) || appnamejy.length<=0){
alert("请输入作品名称并且名称不能为空格");
document.getElementById("appName").value=trim(appname);
document.getElementById("appName").focus();
return false;
}else{

var cArr5 = appname.match(/[^\x00-\xff]/ig);
if (cArr5 != null)
chineseLength = multiple * cArr5.length - cArr5.length;
//var count5 = appname.length + chineseLength;
var count5=getLen(appname);
var remain5 = 200 - count5;
if(remain5<0){
alert("您输入的作品名称过长,请精简后再重新输入");
document.getElementById("appName").focus();
return false;
}
document.getElementById("appName").value=trim(appname);

if(appname=="1"){
alert("作品名称存在关键字,请重新填写");
document.getElementById("appName").focus();
return false;
}
if($("#cntexit").val()!=null&&$("#cntexit").val()!=""){
// 作品说明
var yysm = $("#yysm").val();
var remarks = $("#remarks").val();
var copyright = $("#copyright").val();
var strategy = $("#strategy").val();
var guidance = $("#guidance").val();
if(null != yysm && "" != yysm){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "yysm="+yysm+"&remarks="+remarks+"&copyright="+copyright+"&strategy="+strategy+"&guidance="+guidance,
   // dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="yysmError"){
   $("#yysm").empty();
alert("作品说明包含敏感字符,请重新输入");
return false;
   }else if(data =="remarksError"){
   $("#remarks").empty();
alert("备注信息包含敏感字符,请重新输入");
return false;
   }else if(data =="copyrightError"){
   $("#copyright").empty();
alert("版权说明包含敏感字符,请重新输入");
return false;
   }else if(data =="strategyError"){
   $("#strategy").empty();
alert("作品攻略包含敏感字符,请重新输入");
return false;
   }else if(data =="guidanceError"){
   $("#guidance").empty();
alert("操作指南包含敏感字符,请重新输入");
return false;
   }else{
   if (checkform())
        {
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/cnt_insertCnt.action");
$("#form1").submit();
    }
   }
   }
}
});
}
}else{
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkCntName.action",
   data: "appname="+appname,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="cntNameExist"){
alert("作品名称不能重复");
return false;
   }else if(data=="cntNameSensitivity"){
   alert("作品名称包含敏感字符");
return false;
   }else{
   //验证标签是否存在敏感字符
   var mark = $("#keywords2").val();
   if(null != mark && "" != mark){
   $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkCntMark.action",
   data: "mark="+mark,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("作品标签包含敏感字符");
return false;
   }else{
      //作品说明
var yysm = $("#yysm").val();
var remarks = $("#remarks").val();
var copyright = $("#copyright").val();
var strategy = $("#strategy").val();
var guidance = $("#guidance").val();
if(null != yysm && "" != yysm){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "yysm="+yysm+"&remarks="+remarks+"&copyright="+copyright+"&strategy="+strategy+"&guidance="+guidance,
   // dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="yysmError"){
   $("#yysm").empty();
alert("作品说明包含敏感字符,请重新输入");
return false;
   }else if(data =="remarksError"){
   $("#remarks").empty();
alert("备注信息包含敏感字符,请重新输入");
return false;
   }else if(data =="copyrightError"){
   $("#copyright").empty();
alert("版权说明包含敏感字符,请重新输入");
return false;
   }else if(data =="strategyError"){
   $("#strategy").empty();
alert("作品攻略包含敏感字符,请重新输入");
return false;
   }else if(data =="guidanceError"){
   $("#guidance").empty();
alert("操作指南包含敏感字符,请重新输入");
return false;
   }else{
   if (checkform())
        {
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/cnt_insertCnt.action");
$("#form1").submit();

    }
   }
   }
}
});
}else{
alert("作品说明不能为空");return false;
}
   }
   }

   }
   });   
   }else{
   alert("请输入所需标签并且不能为空格");return false;
   }
}
}
}
});
}
}
   });
           
//点击下一步
$("#next,#lastcurrent").bind("click",function(){
$("#saveORnext").val("next");
var chineseLength = 0;
         var multiple = 3;

var require = /.+/ ; // 必填
   // 校验名称
var appname = $('#appName').val();
var appnames=appname.split(" ");
appnamejy="";
for(var i=0;i<appnames.length;i++){
appnamejy=appnamejy+appnames[i];
}
if(!require.test(appname) || appnamejy.length<=0){
alert("请输入作品名称并且名称不能为空格");
document.getElementById("appName").value=trim(appname);
document.getElementById("appName").focus();
return false;
}else{

var cArr5 = appname.match(/[^\x00-\xff]/ig);
if (cArr5 != null)
chineseLength = multiple * cArr5.length - cArr5.length;
//var count5 = appname.length + chineseLength;
var count5 = getLen(appname);
var remain5 = 200 - count5;
if(remain5<0){
alert("您输入的作品名称过长,请精简后再重新输入");
document.getElementById("appName").focus();
return false;
}
document.getElementById("appName").value=trim(appname);
if(appname=="1"){
alert("作品名称存在关键字,请重新填写");
document.getElementById("appName").focus();
return false;
}
if($("#cntexit").val()!=null&&$("#cntexit").val()!=""){
// 作品说明
var yysm = $("#yysm").val();
var remarks = $("#remarks").val();
var copyright = $("#copyright").val();
var strategy = $("#strategy").val();
var guidance = $("#guidance").val();
if(null != yysm && "" != yysm){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "yysm="+yysm+"&remarks="+remarks+"&copyright="+copyright+"&strategy="+strategy+"&guidance="+guidance,
   // dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="yysmError"){
   $("#yysm").empty();
alert("作品说明包含敏感字符,请重新输入");
return false;
   }else if(data =="remarksError"){
   $("#remarks").empty();
alert("备注信息包含敏感字符,请重新输入");
return false;
   }else if(data =="copyrightError"){
   $("#copyright").empty();
alert("版权说明包含敏感字符,请重新输入");
return false;
   }else if(data =="strategyError"){
   $("#strategy").empty();
alert("作品攻略包含敏感字符,请重新输入");
return false;
   }else if(data =="guidanceError"){
   $("#guidance").empty();
alert("操作指南包含敏感字符,请重新输入");
return false;
   }else{
   if (checkform()){
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/cnt_insertCnt.action");
$("#form1").submit();
  }
   }
   }
}
});
}else{
alert("作品说明不能为空");
return false;
}
}else{
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkCntName.action",
   data: "appname="+appname,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="cntNameExist"){
alert("作品名称不能重复");
return false;
   }else if(data=="cntNameSensitivity"){
   alert("作品名称包含敏感字符");
return false;
   }else{
   //作品标签敏感字符验证
   var mark = $("#keywords2").val();
   if(null != mark && "" != mark){
   $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkCntMark.action",
   data: "mark="+mark,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("作品标签包含敏感字符");
return false;
   }else{
   // 作品说明
var yysm = $("#yysm").val();
var remarks = $("#remarks").val();
var copyright = $("#copyright").val();
var strategy = $("#strategy").val();
var guidance = $("#guidance").val();
if(null != yysm && "" != yysm){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "yysm="+yysm+"&remarks="+remarks+"&copyright="+copyright+"&strategy="+strategy+"&guidance="+guidance,
   // dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="yysmError"){
   $("#yysm").empty();
alert("作品说明包含敏感字符,请重新输入");
return false;
   }else if(data =="remarksError"){
   $("#remarks").empty();
alert("备注信息包含敏感字符,请重新输入");
return false;
   }else if(data =="copyrightError"){
   $("#copyright").empty();
alert("版权说明包含敏感字符,请重新输入");
return false;
   }else if(data =="strategyError"){
   $("#strategy").empty();
alert("作品攻略包含敏感字符,请重新输入");
return false;
   }else if(data =="guidanceError"){
   $("#guidance").empty();
alert("操作指南包含敏感字符,请重新输入");
return false;
   }else{
   if (checkform())
        {
        $("#cntexit").val("1");
$("#appName").attr("readonly","readonly");
$("#form1").attr("action","<%=request.getContextPath() %>/cntportal/cnt_insertCnt.action");
$("#form1").submit();
    }
   }
  
   }
}
});
}else{
alert("作品说明不能为空");return false;
}
}
}
}
});
}else{
   alert("请输入所需标签并且不能为空格");
   return false;
   }

   }   
   }
}
});
}
}
   
   });
//点击“下一步”成功返回方法
window.nextSuccess = function(log){
//如果已保存作品,就设为1
$("#cntexit").val("1");
$("#appName").attr("readonly","readonly");
$(".imgareaselect-outer").hide();
$(".imgareaselect-border4").parent("div").hide();
$("#fd1").hide();
$("#fd2").show();
$("#ruanjianbao").focus();
}  

//保存草稿成功返回方法
window.SaveSuccess = function(log){
//如果已保存作品,就设为1
$("#cntexit").val("1");
$("#appName").attr("readonly","readonly");
alert("保存草稿成功");
}
    // 敏感字
    window.docheck = function(er, type1){
        var url = "<%=request.getContextPath()%>/servlet/filtercheck?name=" + er + "&type=" + type1 + "";
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        }
        else
            if (window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        
        if (req) {
            req.open("GET", url, true);
            req.onreadystatechange = callback;
            req.send(null);
        }
    }
window.callback = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                parseMessage();
            }
            else {
                alert("没有" + req.statusText);
            }
        }
    }
  
  
  
window.parseMessage = function() {
        var xmlDoc = req.responseXML.documentElement;
        var xml = xmlDoc.getElementsByTagName('model');
        var zh = xml[0].childNodes[0].firstChild.nodeValue;
        var type = xml[0].childNodes[1].firstChild.nodeValue;
       
        if (type == "0" && zh=="true") {
            alert("作品名称存在敏感字");
        }
        if(type=="0"){
$("#backname").val((zh == "true") ? "1" : "0");
}else if(type=="1"){
$("#decname").val((zh == "true") ? "1" : "0");
}
    }
   
function checkform(){
var require = /.+/ ; // 必填

// 检验文本
var multiple = 3;
var chineseLength = 0;



// 版本号
var banben = $('#banben').val();
var banbens=banben.split(" ");
banbensjy="";
for(var i=0;i<banbens.length;i++){
banbensjy=banbensjy+banbens[i];
}
if(banben.length>0 && banbensjy.length<=0){
alert("作品版本不能为空格")
document.getElementById("banben").focus();
return false;
}
<%--if(null==banben||""==banben){
alert("请输入作品版本,不能为空");
return false;
}--%>
if(getLen(banben)>18){
alert("作品版本长度不能大于18个字符(汉字算3个),请精简");
return false;
}
var banbens=banben.split(" ");
banben="";
for(var i=0;i<banbens.length;i++){
banben=banben+banbens[i];
}
document.getElementById("banben").value=banben;


//作品分类
var yy2=document.getElementById("select2").value;
var yy3=document.getElementById("select3").value;

if(yy2==null || trim(yy2)=="" || yy3==null || trim(yy3)==""){
alert("作品分类不能为空");
return false;
}


// 校验价格
var double = /^[-\+]?\d+(\d+)?$/ ;
var fee = $('#fee').val();
if (!require.test(fee)) {
alert("请输入价格");
document.getElementById("fee").focus();
return false;
} else {
if(!double.test(fee)){
alert("请输入正确价格")
document.getElementById("fee").focus();
return;
}
else if(fee<0){
alert("价格不能小于0分");
document.getElementById("fee").focus();
return false;
}
else if(fee>10000){
alert("价格不能大于10000分");
document.getElementById("fee").focus();
return false;
}
}
chineseLength = 0;


// 标签
if($('#keywords2').val()=="如,aa,aa") $('#keywords2').val("");
var keywords2 = $('#keywords2').val();  
var newstr=keywords2.replace(/,/g,",");
var keywords2s=newstr.split(" ");
keywords2jy="";
for(var i=0;i<keywords2s.length;i++){
keywords2jy=keywords2jy+keywords2s[i];
}
//获取标签字段总长度
var cNewstr = newstr.match(/[^\x00-\xff]/ig);
chineseLength = 0;

if(cNewstr != null ){
chineseLength = multiple * cNewstr.length - cNewstr.length;
}
//var countStr = newstr.length + chineseLength;
var countStr = getLen(newstr);
var resultNewStr = 255 - countStr;

if(!require.test(keywords2) ||keywords2jy.length<=0 ){
alert("请输入所需标签并且不能为空格")
document.getElementById("keywords2").focus();
return false;
}else if(resultNewStr < 0){
alert("标签总长度不能大于255个字符")
document.getElementById("keywords2").focus();
return false;
}else{
var str = new Array();
str = newstr.split(",");

for(var k = 0; k < str.length; k++){
//获取每个标签长度
var cStrArr = str[k].match(/[^\x00-\xff]/ig);
chineseLength = 0;

if(cStrArr != null ){
chineseLength = multiple * cStrArr.length - cStrArr.length;
}
//var countStr = str[k].length + chineseLength;
var countStr=getLen(str[k]);
var resultLen = 30 - countStr;

if(str[k].replace(/(^\s*)|(\s*$)/g, "")==""){
alert("请确认输入的标签是否多逗号");
document.getElementById("keywords2").focus();
return false;
}
if(resultLen < 0){
    alert("每个标签的长度不能大于30个字符");
    document.getElementById("keywords2").focus();
return false;
}


if(str[k]==str[k-1]){
    alert("请检查标签是否重复");
    document.getElementById("keywords2").focus();
return false;
}
}
if(str.length>5){
alert("最多只能添加五个标签");
document.getElementById("keywords2").focus();
return false;
}
$('#keywords2').val(newstr);
}
chineseLength = 0;
// 作品说明
var yysm = $("#yysm").val();
if(!require.test(yysm)){
alert("请输入作品说明")
document.getElementById("yysm").focus();
return false;
}
yysm=trim(yysm);
if(!require.test(yysm)){
alert("作品说明不能只为空格");
document.getElementById("yysm").value="";
document.getElementById("yysm").focus();
return false;
}

var cArr = yysm.match(/[^\x00-\xff]/ig);
if (cArr != null)
chineseLength = multiple * cArr.length - cArr.length;
//var count = yysm.length + chineseLength;
var count = getLen(yysm);
var remain = 2000 - count;
if(remain<0){
alert("您输入的作品说明内容过长,请精简后再重新输入");
document.getElementById("yysm").focus();
return false;
}
chineseLength = 0;
// 操作指南
var guidance = $("#guidance").val();
var cArr1 = guidance.match(/[^\x00-\xff]/ig);
if (cArr1 != null)
chineseLength = multiple * cArr1.length - cArr1.length;
//var count1 = guidance.length + chineseLength;
var count1 = getLen(guidance);
var remain1 = 2000 - count1;
if(remain1<0){
alert("您输入的作品操作指南过长,请精简后再重新输入");
document.getElementById("guidance").focus();
return false;
}
chineseLength = 0;
// 作品攻略
var strategy = $("#strategy").val();
var cArr2 = strategy.match(/[^\x00-\xff]/ig);
if (cArr2 != null)
chineseLength = multiple * cArr2.length - cArr2.length;
//var count2 = strategy.length + chineseLength;
var count2 = getLen(strategy);
var remain2 = 2000 - count2;
if(remain2<0){
alert("您输入的作品作品攻略过长,请精简后再重新输入");
document.getElementById("strategy").focus();
return false;
}
chineseLength = 0;
// 版权说明
var copyright = $("#copyright").val();
var cArr3 = copyright.match(/[^\x00-\xff]/ig);
if (cArr3 != null)
chineseLength = multiple * cArr3.length - cArr3.length;
//var count3 = copyright.length + chineseLength;
var count3 = getLen(copyright);
var remain3 = 2000 - count3;
if(remain3<0){
alert("您输入的作品版权说明过长,请精简后再重新输入");
document.getElementById("copyright").focus();
return false;
}
chineseLength = 0;
// 备注
var remarks = $("#remarks").val();
var cArr4 = remarks.match(/[^\x00-\xff]/ig);
if (cArr4 != null)
chineseLength = multiple * cArr4.length - cArr4.length;
//var count4 = remarks.length + chineseLength;
var count4 = getLen(remarks);
var remain4 = 2000 - count4;
if(remain4<0){
alert("您输入的作品备注过长,请精简后再重新输入");
document.getElementById("remarks").focus();
return false;
}

//版本附件格式及大小
<%--
var fjsize=document.getElementById("copyrightfile").value;
var fjlx=/\.gif$|\.pdf$|\.bmp$|\.jpg$|\.png$|\.rar$|\.zip$/i;
var indexfj = fjsize.lastIndexOf("\\");
var fjname=fjsize.substr(indexfj+1);
if(!fjlx.test(fjname) && fjname!=null && fjname!=""){
alert("附件格式不正确,只能上传以下图片格式:gif,pdf,bmp,jpg,png,rar,zip");
return false;
}

--%>

//版本附件格式及大小

var fjsize=document.getElementById("copyrightfile").value;
if(null!=fjsize&&fjsize.length>0){
var index1 = fjsize.lastIndexOf("\\");
var fjname=fjsize.substr(index1+1);
var index2 = fjname.lastIndexOf(".");
if(index2>0&&index2<fjname.length){
var type=fjsize.substr(index2+1);;
}else{
alert("版本附件格式不正确,请重新选择");
return false;
}
}


//用户自测情况表格式及大小

var testfile=document.getElementById("testfile").value;
if(null!=testfile&&testfile.length>0){
var index1 = testfile.lastIndexOf("\\");
var fjname=testfile.substr(index1+1);
var index2 = fjname.lastIndexOf(".");
if(index2>0&&index2<fjname.length){
var type=fjsize.substr(index2+1);
}else{
alert("用户自测情况表格式不正确,请重新选择");
return false;
}
}

if(null==$("#imageName").val()||""==$("#imageName").val()){
alert("请先保存截图");
return false;
}

if(saveImg!=1){
alert("请先保存截图");
return false;
}


if(figure1+figure2+figure3+figure4<1){
alert("请先选择截图");
return false;

}

return true;

}
    })(jQuery);
   
   
    (function($){
var cs1;
var cs2;
   window.saveInit = function() {
   cs1=$("#zxtdiv").clone(true);
   cs2=$("#ppdiv").clone(true);
   }
  
    window.runpicremove=function(picid){
   $('#'+picid+1).empty();
   $('#'+picid+1).append("<input type=\"file\" name='"+picid+"' "+
   "id=\""+picid+"\" onchange=\"onUploadImg('"+picid+"')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />");
   } 
  
   window.runpicremove1=function(picid,previewid,px,example1id){
   $('#'+picid+1).empty();
   $('#'+picid+1).append("<input type=\"file\" name='"+picid+"' "+
   "id=\""+picid+"\" onchange=\"onUploadImg('"+picid+"')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />");
   $('#'+previewid).empty();
   $('#'+previewid).append("<img src=\"<%=request.getContextPath()%>/images/default.gif\" class=\"photo90-120p\" id=\""+px+"\" onload=\"onPreviewLoad(this)\"/>");
   $('#'+example1id).empty();
   $('#'+example1id).append("default.gif");
   if(picid=="pic1"){
   figure1=0;
   }
   if(picid=="pic2"){
   figure2=0;
   }
   if(picid=="pic3"){
   figure3=0;
   }
   if(picid=="pic4"){
   figure4=0;
   }
   $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_delPreView.action",
   data: "type=add"+"&pic="+picid,
   dataType: "text",
   success: function(data){}
});
   } 
   window.runpicremove2=function(picid,previewid,px,example1id){

   $('#'+picid+1).empty();
   $('#'+picid+1).append("<input type=\"file\" name='pic2' "+
   "id=\""+picid+"\" onchange=\"onUploadImg('pic2')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />");
   $('#'+previewid).empty();
   $('#'+previewid).append("<img src=\"<%=request.getContextPath()%>/images/default.gif\"  id=\""+px+"\" />");
   $('#'+example1id).empty();
   $('#'+example1id).append("default.gif");
   }
   window.runpicremove3=function(picid,previewid,px,example1id){

   $('#'+picid+1).empty();
   $('#'+picid+1).append("<input type=\"file\" name='pic3' "+
   "id=\""+picid+"\" onchange=\"onUploadImg('pic3')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />");
   $('#'+previewid).empty();
   $('#'+previewid).append("<img src=\"<%=request.getContextPath()%>/images/default.gif\"  id=\""+px+"\" />");
   $('#'+example1id).empty();
   $('#'+example1id).append("default.gif");
   }
   window.runpicremove4=function(picid,previewid,px,example1id){

   $('#'+picid+1).empty();
   $('#'+picid+1).append("<input type=\"file\" name='pic4' "+
   "id=\""+picid+"\" onchange=\"onUploadImg('pic4')\" onmousedown=\"this.oncontextmenu = function(){return false;}\" "+
   "onkeydown=\"return false;\" class=\"width360p input2 marginbottom5p\" size=\"40\" />");
   $('#'+previewid).empty();
   $('#'+previewid).append("<img src=\"<%=request.getContextPath()%>/images/default.gif\"  id=\""+px+"\" />");
   $('#'+example1id).empty();
   $('#'+example1id).append("default.gif");
   }
  
   $("#jxss").bind("click",function(){
           $(this).val("");
   });
 
  
   window.checkall = function() {
        var cmps = document.getElementsByName("cmp");
        if ($("#all").attr("checked")) {
            for (var i = 0; i < cmps.length; i++) {
                cmps[i].checked = true;
            }
        }
        else {
            for (var i = 0; i < cmps.length; i++) {
                cmps[i].checked = false;
            }
        }
    }
   
   
    // 查询二级分类
$("#select2").bind("change",function(){
var parentcatindex=$("#select2").val();
if(parentcatindex==null||trim(parentcatindex)==''){
$("#select3").empty();
}else{

    $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_getCategory.action",
   data: "mproductCategory.parentcatindex="+parentcatindex,
   dataType: "json",
   success: function(data){
   if(data!=null&&""!=data){
   $("#select3").empty();
   $.each(data,function(index,content){
   $("<option  value='"+content['catindex']+"'>"+content['catname']+"</option>").appendTo("#select3");
   });
   }else{
   $("#select3").empty();
   }
}
});
}
});
     
   
    // 查找操作系统子平台
 
     $(".oscheckbox").click(function(){
     
    var osindex = $(this).val();
   
    if($(this).attr("checked")){
    $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_getOS.action",
   data: "mtmlOs.ostype="+osindex,
   dataType: "json",
   success: function(data){
   $.each(data,function(index,content){
   $("<label class='class"+osindex+"' for='a1'><input type='checkbox' value='"+content['osindex']+"'  class='zxtlcheckbox"+osindex+"' zhi='1' name='zxtl' checked='true'/>"+content['osname']+content['osversion']+"</label>").appendTo("#zxtdiv");
   });
   }
});
    }else{
     $(".class"+osindex+"").remove();
    }
       
});

// 筛选终端
$("#queryTerminal").click(function(){

  var flag=true;
  $(".oscheckbox").each(function (i) {
if($(this).attr("checked")){
var oscheckboxindex=$(this).val();
var oscheckboxname=$(this).attr("zhi");
var osindex=0;
$(".zxtlcheckbox"+oscheckboxindex).each(function (i) {
if($(this).attr("checked")){
osindex++;
}
});
if(osindex<1){
alert("至少保留一个"+oscheckboxname+"操作系统子平台");
flag = false;
}
}
});

if(!flag){
return false;
}

var os=new Array();
var zxtlcbx=0;
var osindex=0;

if($("input[name='zxtl']").length>0){
$("input[name='zxtl']").each(function (i) {
if($(this).attr("checked")){
zxtlcbx+=1;
os[osindex]=$(this).val();
osindex++;
}
});

}else{

os="";
}


var isfou="";
if($("#isfou").is(":checked")){
isfou=$("#isfou").val();
}
var cmp=new Array();
var cmpindex=0;
$("input[name='cmp']").each(function (i) {
if($(this).attr("checked")){
cmp[cmpindex]=$(this).val();
cmpindex++;
}
});
$("#queryTerminal").attr("disabled","disabled");
setTimeout("$('#queryTerminal').attr('disabled','');",3000);
    $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_getTerminal.action",
   data: "os="+os+"&resolu="+cmp+"&mtmlInfo.issupportjava="+isfou,
   dataType: "json",
   success: function(data){
   $("#leftmodel").empty();
   if(data!=null&&""!=data){
  
   $.each(data,function(index,content){
   $("<option  value='"+content['terminalindex']+"'>"+content['terminalmodelname']+"</option>").appendTo("#leftmodel");
   });
  
   $("#pinpai").empty();
   $("<option  value=''>--请选择--</option>").appendTo("#pinpai");
   $.each(data,function(index,content){
  
   var flag=0;
   for(var j=0;j<$("#pinpai option").length;j++){
   if($("#pinpai option")[j].value==content['brandindex']){
   flag=flag+1;
   }
   }
   if(flag==0){
   $("<option  value='"+content['brandindex']+"'>"+content['brandname']+"</option>").appendTo("#pinpai");
   }
   });
  
   }
   $("#queryTerminal").attr("disabled","");
}

});

});

<%-- //1.作品说品绑定信息
$("#yysm").bind("change",function(){
// 作品说明
var yysm = $("#yysm").val();
if(null != yysm && "" != yysm){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "content="+yysm,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("作品说明包含敏感字符,请重新输入");
return false;
   }
   }
}
});
}
});

//2.操作指南绑定信息
$("#guidance").bind("change",function(){
// 操作指南
var guidance = $("#guidance").val();
if(null != guidance && "" != guidance){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "content="+guidance,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("操作指南包含敏感字符,请重新输入");
return false;
   }
   }
}
});
}
});

//3.作品攻略绑定信息
$("#strategy").bind("change",function(){
// 作品攻略
var strategy = $("#strategy").val();
if(null != strategy && "" != strategy){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "content="+strategy,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("作品攻略包含敏感字符,请重新输入");
return false;
   }
   }
}
});
}
});

//4.版权说明绑定信息
$("#copyright").bind("change",function(){
// 版权说明
var copyright = $("#copyright").val();
if(null != copyright && "" != copyright){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "content="+copyright,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("版权说明包含敏感字符,请重新输入");
return false;
   }
   }
}
});
}
});

//5.备注绑定信息
$("#remarks").bind("change",function(){
// 备注
var remarks = $("#remarks").val();
if(null != remarks && "" != remarks){
$.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_checkSensitword.action",
   data: "content="+remarks,
   dataType: "text",
   success: function(data){
   if(data!=null&&""!=data){
   if(data=="false"){
alert("备注信息包含敏感字符,请重新输入");
return false;
   }
   }
}
});
}
});
--%>

// 根据品牌再次筛选终端
$("#pinpai").bind("change",function(){
var brandindex=$("#pinpai").val();

if(brandindex==null||brandindex==""){

}else{
var flag=true;
  $(".oscheckbox").each(function (i) {
if($(this).attr("checked")){
var oscheckboxindex=$(this).val();
var oscheckboxname=$(this).attr("zhi");
var osindex=0;
$(".zxtlcheckbox"+oscheckboxindex).each(function (i) {
if($(this).attr("checked")){
osindex++;
}
});
if(osindex<1){
alert("至少保留一个"+oscheckboxname+"操作系统子平台");
flag = false;
}
}
});

if(!flag){
return false;
}

var os=new Array();
var zxtlcbx=0;
var osindex=0;

if($("input[name='zxtl']").length>0){
$("input[name='zxtl']").each(function (i) {
if($(this).attr("checked")){
zxtlcbx+=1;
os[osindex]=$(this).val();
osindex++;
}
});

}else{

os="";
}


var isfou="";
if($("#isfou").is(":checked")){
isfou=$("#isfou").val();
}
var cmp=new Array();
var cmpindex=0;
$("input[name='cmp']").each(function (i) {
if($(this).attr("checked")){
cmp[cmpindex]=$(this).val();
cmpindex++;
}
});

    $.ajax({
   type: "POST",
   url: "<%=request.getContextPath()%>/cntportal/ajax_getTerminal.action",
   data: "os="+os+"&resolu="+cmp+"&mtmlInfo.issupportjava="+isfou+"&mtmlInfo.brandindex="+brandindex,
   dataType: "json",
   success: function(data){
   $("#leftmodel").empty();
   if(data!=null&&""!=data){
   $.each(data,function(index,content){
   $("<option  value='"+content['terminalindex']+"'>"+content['terminalmodelname']+"</option>").appendTo("#leftmodel");
   });
   }
}
});
}
});

// 机型搜索
$("#selectjx").bind("click",function(){

var jxss=$("#jxss").val();

//验证是否是英文字母和数字
var patrn = /^[a-zA-Z0-9]+$/;
    if(patrn.exec(jxss)==null){
    alert("终端机型只能为英文字母和数字");
    return false;
    }
if($("#zdlb").is(":checked")){
var flag=true;
  $(".oscheckbox").each(function (i) {
if($(this).attr("checked")){
var oscheckboxindex=$(this).val();
var oscheckboxname=$(this).attr("zhi");
var osindex=0;
$(".zxtlcheckbox"+oscheckboxindex).each(function

你可能感兴趣的:(Ajax,json,jsp,css,OS)