this might get abit confusing but here it goes.

这可能会让人感到困惑,但现在就这样了。

I have a masterpage called UserProfile.master it has a contentplaceholder linked to UserProfileWall.aspx now im trying to load some javascript and a second css file in the userprofilewall page but when ever I add a second link to the css file it screws up everything on the master page. I cant put the css link in the userprofilewall contentplaceholder because it says link can not be nested in div table which brings me to the javascript and div table.

我有一个名为UserProfile.master的母版页,它有一个链接到UserProfileWall.aspx的contentplaceholder现在我试图在userprofilewall页面加载一些javascript和第二个css文件但是当我添加第二个链接到css文件时它会搞砸一切母版页。我不能把css链接放在userprofilewall contentplaceholder中,因为它说链接不能嵌套在div表中,这会将我带到javascript和div表。

The java script just runs a button click event for adding text from a textarea into the div. But for some reason it doesnt work. Not without the second css

java脚本只运行一个按钮单击事件,用于将文本从textarea添加到div中。但由于某种原因,它不起作用。不是没有第二个CSS

This is what I would like to insert in the second css:

这是我想在第二个css中插入的内容:

div{
    width:400px;
    height:400px;
    border:1px solid red;
    padding:10px;
    margin-top:10px;
}

my code so far for the entire userprofilewall

我的代码到目前为止整个userprofilewall

<%@ Page Title="" Language="C#" MasterPageFile="~/UserProfile.master" AutoEventWireup="true" CodeFile="UserProfileWall.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="css/Style.css" rel="stylesheet" type="text/css" />

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $('button').click(function () {
        var x = $('textarea').val();
        $('div').html(x);
    });
        </script>
<textarea style="border: 0" cols="77" rows="5"></textarea>
<button>Post Message</button>

<div></div>

</asp:Content>

how do i go about either fixing the javascript or fixing the css into my userprofilewall so the javascript can pick up on it

我如何修复javascript或修复css到我的userprofilewall所以javascript可以拿起它

1 个解决方案

#1


0

First, I needed to fix the Javascript to add the button click handler in a $(document).ready() call, not as inline script code. This fixed the "Post Message" button issue. Next up, how to handle the style change of the div...

首先,我需要修复Javascript以在$(document).ready()调用中添加按钮单击处理程序,而不是内联脚本代码。这修复了“发布消息”按钮的问题。接下来,如何处理div的样式更改...

For now, I've added a .css() call to set the css properties you defined in your question inline in the click handler, but you would probably want to move these css properties into a single CSS rule and use .addClass() and .removeClass()

现在,我已经添加了一个.css()调用来设置您在单击处理程序中内联问题中定义的css属性,但您可能希望将这些css属性移动到单个CSS规则中并使用.addClass()和.removeClass()

Here are some links to check out regarding the changes I made:

以下是一些链接,可以查看我所做的更改:

$(document).ready()

.css()

.addClass()

.removeClass()

Here's the source I used to fix the JS and CSS issues, from a static HTML page I created from your source code. Hope it helps.

这是我用来修复JS和CSS问题的源代码,来自我从源代码创建的静态HTML页面。希望能帮助到你。

<html>
<head>
   <link href="css/Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('button').click(function () {
        var x = $('textarea').val();
        $('div').html(x);
        $('div').css({width:"400px",height:"400px",border:"1px solid red",padding:"10px","margin-top":"10px"});
        // or $('div').addClass('name of css rule with above css props');
        // or $('div').removeClass('name of css rule with above css props');
    });
});
</script>
<textarea style="border: 0" cols="77" rows="5"></textarea>
<button>Post Message</button>
<div></div>
</body>
</html>

更多相关文章

  1. jQuery -添加活动类并在单击时从其他元素中删除活动类
  2. JavaScript / jQuery:如何链接使用console.log()的方法
  3. 确定焦点事件:单击或tabstop
  4. 单击文件输入后,Fancybox正在关闭
  5. 禁用链接以停止在JQuery中双击
  6. 如何使用jQuery捕获对href值的单击
  7. jQuery图片热点链接添加编辑插件
  8. 单击列表项时如何编写内容? [重复]
  9. 如何在HTML中为移动页面创建图像下载链接?

随机推荐

  1. go引入外部依赖的三种方式介绍
  2. golang怎么debug
  3. 安装go第三方库的方法
  4. go语言之goroute协程
  5. golang写爬虫乱码怎么办
  6. Go接口interface的用法介绍
  7. Go语言执行流程详解
  8. golang能写操作系统吗
  9. golang如何判断字符串是否为空
  10. golang如何判断目录是否存在