function getTextOverflow() { $('.xwzx-detail-box').each(function (index) { var $container = $(this) var $content = $(this).children('.xwzx-detail') var str = $content.text().trim() if ($content.height() > $container.height()) { for (var i = 0; i <= str.length; i++) { $content.text(str.slice(0, i)) if ($content.height() > $container.height()) { $content.text(str.slice(0, i - 3) + "..."); break; } } } }); } function getYWTextOverflow(num) { $('.service-detail-box').each(function (index) { var $content = $(this).children('p') var str = $content.text().trim() if (str.length > num) { $content.text(str.slice(0, num - 3) + "..."); } }); } function setTextOverflow(parentDom, childDom) { $(parentDom).each(function (index) { var $container = $(this) var $content = $(this).children(childDom) var str = $content.text().trim() if ($content.height() > $container.height()) { for (var i = 0; i <= str.length; i++) { $content.text(str.slice(0, i)) if ($content.height() > $container.height()) { $content.text(str.slice(0, i - 3) + "..."); break; } } } }); } $(function () { // todo 閫傞厤鎵嬫満绔 001 // var winWidth = $(window).width(); // $('.bannar-box-img').each(function (index) { // var imgsrc = $(this).attr('src'); // console.log(index) // if (winWidth <= 800) { // $(this).attr('src', 'src/img/banner' + 1 + '-m.jpg'); // } else { // $(this).attr('src', 'src/img/banner' + 1 + '.jpg'); // } // }) // todo 閫傞厤鎵嬫満绔 001 $('.xwzx-box').ready(function ($) { getTextOverflow(); }); //鏂伴椈鍒楄〃120涓瓧绗 $('.service-list').ready(function ($) { getYWTextOverflow(120) }); }); function resetMessageForm() { $("#name").val(''); $("#phone").val(''); $("#message").val(''); $("#error-message").hide(); } function submitMessage() { // debugger var name = $("#name").val(); var phone = $("#phone").val(); var message = $("#message").val(); var errMsg = '' if (!name.trim()) { errMsg = '璇疯緭鍏ユ偍鐨勭О鍛? } else if (!phone.trim()) { errMsg = '璇疯緭鍏ユ偍鐨勮仈绯绘柟寮? }else if (phone.trim().length !==11) { errMsg = '鎵嬫満鍙锋牸寮忎笉姝g‘' } else if (!message.trim()) { errMsg = '璇疯緭鍏ユ偍鐨勭暀瑷€' } if (errMsg) { $("#error-message").text(errMsg); $("#error-message").show(); return } else { $("#error-message").hide(); } var params = { name: name, phone: phone, content: message } $.post("/message", params, function (data, status) { alert('鍙嶉鎴愬姛'); $("#name").val(''); $("#phone").val(''); $("#message").val(''); }); }