输入按钮与onclick Java脚本函数未触发

input button with onclick java script function not firing

本文关键字:函数 脚本 Java 按钮 onclick 输入      更新时间:2023-09-26

我的javascript按钮没有触发。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    </head>
<body>
    <form id="form1" runat="server">
    <script   type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    <div>
<script language="javascript" type="text/javascript">
    FB.init({
        appId: '185176734893804',
        status: true,
        cookie: true,
        xfbml: true
    });

   function fb_publish() {
     FB.ui(
       {
         method: 'stream.publish',
         message: document.getElementById('<%=TextBox1.ClientID%>').value,
         attachment: {
           name: 'Friends Gathering',
           caption: 'Healthy living',
           description: (
             'Your welcome to join us on the event'
           ),
           href: 'thomasblog.somee.com'
         },
         action_links: [
           { text: 'document.getElementById('<%=TextBox1.ClientID%>').value', href: 'thomasblog.somee.com' }
         ],
         user_prompt_message: 'Personal message here'
       },
       function(response) {
         if (response && response.post_id) {
           alert('Post was published.');
         } else {
           alert('Post was not published.');
         }
       }
     );  
  }
  </script>
 </div>
    <div>

        Event Date:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        Event Title:
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Add Event" />
        <br />
        <br />
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
            <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="2px" 
                Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
        </asp:Calendar>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
         <input type="button" onclick="fb_publish()" 
            value ="Post To facebook Wall" />
    </div>
    </form>
</body>
</html>

这就是我正在尝试的。点击html按钮类型。Fb_publish应该触发。这只是我的尝试…不确定它是否应该工作。在fb_publish()中,我有一个FB。UI来发布textbox1。文本和其他事件详细信息到FB

试试这个,在输入标记中添加和id,并在文档加载后使用事件触发器。并在函数的开头放置一个警告,以确保它正在被调用。

 <script> document.ready( function (){
    $('#fb_button').onClick( function(){
alert('button fired');
    fb_publish();
    }
    }
    </script>