我有一个div,其ID为controlContainer
,另外3个div
,其display
为none
,我将使用jQuery对其进行追加和添加,并更改{从{1}}模式切换到display
,但无效。
block
$(document).ready(function() {
var i = 1;
if (i = 1) {
var group = $('#beforeUpload').clone().attr("id", "beforeUpload" + i);
$(group).css("Display", "block");
$(group).appendTo("#controlContainer");
var group2 = $("#uploadHeading").clone().attr("id", "uploadHeading" + i);
$(group).css("Display", "block");
$("#beforeUpload" + i).prepend(group2);
var group5 = $('#afterUpload').clone().attr("id", "afterUpload" + i);
$(group).css("Display", "block");
$(group5).appendTo("#beforeUpload" + i);
}
});
答案 0 :(得分:1)
首先,您的显示应该在css中显示不正确,其次,您没有追加到正确的组,并且我还更新了最新的jquery版本。
这将为您工作:
Sub saveWithLogo()
Dim fd As FileDialog
Dim directory As String
Dim vrtSelectedItem As Variant
Dim osld As Slide
Dim oPic As Shape
Dim osldGroup As Slide
Dim oshp As Shape
Dim logoPic As Shape
Dim i As Integer
Dim num_pics As Integer
Dim fso As New FileSystemObject
Dim FileName As String
Dim FilePath As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd 'Get pictures from file dialog, add logo to each picture
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
numPics = .SelectedItems.Count
FileName = fso.GetBaseName(vrtSelectedItem)
FilePath = fso.GetParentFolderName(vrtSelectedItem)
Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
Set oPic = osld.Shapes.AddPicture(vrtSelectedItem, msoFalse, msoTrue, 50, 50)
osldno = ActivePresentation.Slides.Count
logoWidth = 6.18 * 28.3
logoHeight = 1.4 * 28.3
Set logoPic = osld.Shapes.AddPicture("C:\foxpro2\vtools\logo.bmp", lsoFalse, msoTrue, 50, 50, logoWidth, logoHeight)
osld.Select
ActiveWindow.Selection.Unselect
For Each oshp In osld.Shapes
If oshp.Type = msoPicture Then oshp.Select Replace:=False
Next oshp
With ActiveWindow.Selection.ShapeRange
If .Count > 1 Then .Group
End With
FinalName = FilePath & "\" & FileName & "_with logo"
'MsgBox FinalName
osld.Export FinalName & "_with logo", ppShapeFormatJPG ' , 3072
Next vrtSelectedItem
End If
End With
Set fd = Nothing
End Sub
$(document).ready(function () {
var i = 1;
if (i = 1) {
var group = $('#beforeUpload').clone().attr("id", "beforeUpload" + i);
$(group).css("display", "block");
$(group).appendTo("#controlContainer");
var group2 = $("#uploadHeading").clone().attr("id", "uploadHeading" + i);
$(group2).css("display", "block");
$("#beforeUpload" + i).prepend(group2);
var group5 = $('#afterUpload').clone().attr("id", "afterUpload" + i);
$(group5).css("display", "block");
$(group5).appendTo("#beforeUpload" + i);
}
});
答案 1 :(得分:1)
如@Rory McCrossan所述:
1。Display
必须为display
。
2。您已经在多个位置重用了group
变量,而不是正确的groupN
变量。
3。if (i = 1) { //assignment
必须为if (i == 1) { //comparison
更正该错误,您的代码即可使用。
工作片段:-
$(document).ready(function () {
var i = 1;
if (i == 1) { //check with ==
var group = $('#beforeUpload').clone().attr("id", "beforeUpload" + i);
$(group).css("display", "block");
$(group).appendTo("#controlContainer");
var group2 = $("#uploadHeading").clone().attr("id", "uploadHeading" + i);
$(group2).css("display", "block"); // need to be group2 instead of group
$("#beforeUpload" + i).prepend(group2);
var group5 = $('#afterUpload').clone().attr("id", "afterUpload" + i);
$(group5).css("display", "block");// need to be group5 instead of group
$(group5).appendTo("#beforeUpload" + i);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="controlContainer">
<h1>Main Container</h1>
</div>
<div id="beforeUpload" style="display: none;">
<h2>It will append to "Main Container" and this is Before Upload</h2>
</div>
<div id="uploadHeading" style="display: none;">
<h4>It will prepend to "Main Container" and this is Upload Heading</h4>
</div>
<div id="afterUpload" style="display: none;">
<h3>It will append to "Main Container" and this is After Upload</h3>
</div>
</body>
</html>
注意:-尝试使用最新的jQuery库