2015-04-14 48 views
0

下面拨弄尝试火被截断的文本对话框时,选择的href:jQuery的函数对话框未找到

<a href='javascript:void(0)' id="truncatedText" onclick='fnOpenNormalDialog("this is the text to truncate");return false'></a> 

$(function(){ 
$("#truncatedText").text(truncateText('truncate this text')); 
}) 

function truncateText(text) { 

var shortText = jQuery.trim(text).substring(0, 20) .split(" ").slice(0, -1).join(" ") + "..."; 

    console.log(shortText) 
return shortText 

    } 

function fnOpenNormalDialog(text) { 
    $("#dialog-confirm").html("Confirm Dialog Box"); 

    // Define the Dialog and its properties. 
    $("#dialog-confirm").dialog({ 
     resizable: false, 
     modal: true, 
     title: "Modal", 
     height: 250, 
     width: 400, 
     buttons: { 
      "Yes": function() { 
       $(this).dialog('close'); 
       callback(true); 
      }, 
       "No": function() { 
       $(this).dialog('close'); 
       callback(false); 
      } 
     } 
    }); 
} 

的jsfiddle:http://jsfiddle.net/vvjj8/6236/

但功能fnOpenNormalDialog没有被发现,Chrome的错误:

Uncaught ReferenceError: fnOpenNormalDialog is not defined(index):72 onclick 

函数定义不正确?

+0

如果您使用的是jQuery,为什么要使用过时的'onclick'方法? (并且它没有被定义,因为方法的定义在使用之前未被声明)。改变你的演示,以简单地使用头部脚本修复了这个问题,请不要这样做,使用[Document Ready]编写一些好的jQuery代码(http://learn.jquery.com/using-jquery-core/document -ready /)和[jQuery on](https://api.jquery.com/on/)事件处理。 –

+0

哪里是对话确认在小提琴? – Sushil

+0

@Sushil它不工作,因为他已经完全陈述了。 –

回答

0

我已更新您的jsfiddle并添加了缺少的div。

你的链接现在看起来是这样

<a href='#' id="truncatedText"></a> 
<div id='dialog-confirm'></div> 

试试这个http://jsfiddle.net/vvjj8/6242/