麻烦从bootstrap-slider获得价值

时间:2016-05-09 09:31:50

标签: jquery twitter-bootstrap

我正在使用bootstrap slider作为我正在构建的预测工具。我有以下功能:

function updateContractConcern () {

    showLoader();

    var funcid = "call_chart_contract_concern"
    var forecastperiod = $('#forecastslider').data('slider').getValue();
    //var forecastperiod = 4;

    console.log('forecastperiod')

    var jqxhr = $.getJSON('functions/getfunctions.php', {
        "forecastperiod":forecastperiod,
        "funcid":funcid}).done(function(dataChart) {

            hideLoader();

            if (dataChart == null) {
                bootbox.alert("Er is geen data voor deze selectie aanwezig");
            } else {
                setBasicPropertiesAverageScoreChart();
                averageScoreChart.dataProvider = dataChart;
                averageScoreChart.categoryField = "organisatie";
                averageScoreChart.validateData();
              }     
        })
        .fail(function() { hideLoader(); bootbox.alert("Er kon geen data verkregen worden uit de database"); }); //When getJSON request fails
}

我在这里遇到的问题是var forecastperiod = $('#forecastslider').data('slider').getValue();没有给我滑块的值。有什么想法吗?

HTML代码如下:

 <div class=text-center>
    <label id="labelforecastslider"><i class="fa fa-clock-o" id="iconclock"></i>  Bepaal de forecast periode:</label> <!-- Range -->
    <input id="forecastslider" data-slider-id='forecastslider' type="text" data-slider-min="1" data-slider-max="12" data-slider-step="1" data-slider-value="0"/>
 </div>

滑块附带的JavaScript是:

var slider = new Slider("#forecastslider", {
    focus: true,
    formatter: function(value) {
        var months = ['t/m Januari', 't/m Februari', 't/m Maart', 't/m April', 't/m Mei', 't/m Juni', 't/m Juli', 't/m Augustus', 't/m September', 't/m Oktober', 't/m November', 't/m December'];
        return months[value - 1];
    }
});

当我使用var forecastperiod = $('#forecastslider').val();时,没有任何反应,但当我将变量设置为“硬”数字时,var forecastperiod = 2;代码确实有用。

1 个答案:

答案 0 :(得分:1)

由于bootstrap-slider可以看作输入字段,因此您需要使用以下代码:

   public void CreateWordDocument()
   {

       using (MemoryStream DocxMemory = new MemoryStream())
       {
           using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(DocxMemory, WordprocessingDocumentType.Document, true))
           {
               // Add a main document part. 
               MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
               // Create the document structure and add some text.
               this.AddSettingsToMainDocumentPart(mainPart);

               StyleDefinitionsPart part = mainPart.StyleDefinitionsPart;
               // If the Styles part does not exist, add it.  
               if (part == null)
               {
                   this.AddStylesPartToPackage(mainPart);
               }

               mainPart.Document = new Document();
               Body body = mainPart.Document.AppendChild(new Body());
               Paragraph Para = body.AppendChild(new Paragraph());
               Run run = Para.AppendChild(new Run());
               run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("This is main text of the document"));

               var footnotesPart = mainPart.AddNewPart<FootnotesPart>("rId1");

               this.GenerateFooterPartContent(mainPart.FootnotesPart);
               mainPart.Document.Save();
               wordDocument.Close();

               MemoryStream Result = new MemoryStream();
               DocxMemory.Seek(0, SeekOrigin.Begin);
               DocxMemory.CopyTo(Result);
               Result.Position = 0;

               ////Citation processing
               byte[] BufferFileData = new byte[Result.Length];
               Result.Read(BufferFileData, 0, (int)Result.Length);
               File.WriteAllBytes("Output1.docx", BufferFileData);

           }
       }
   }

   private void AddSettingsToMainDocumentPart(MainDocumentPart part)
   {
       DocumentSettingsPart settingsPart = part.DocumentSettingsPart;
       if (settingsPart == null)
           settingsPart = part.AddNewPart<DocumentSettingsPart>();
       settingsPart.Settings = new Settings(
         new Compatibility(
           new CompatibilitySetting()
           {
               Name = new EnumValue<CompatSettingNameValues>
                       (CompatSettingNameValues.CompatibilityMode),
               Val = new StringValue("14"),
               Uri = new StringValue
                       ("http://schemas.microsoft.com/office/word")
           }
      )
   );
       settingsPart.Settings.Save();
   }
   private StyleDefinitionsPart AddStylesPartToPackage(MainDocumentPart mainPart)
   {
       StyleDefinitionsPart part;
       part = mainPart.AddNewPart<StyleDefinitionsPart>();
       Styles root = new Styles();
       root.Save(part);
       return part;
   }

   // Generates content of part.
   private void GenerateFooterPartContent(FootnotesPart part)
   {
       Footnotes footnotes1 = new Footnotes() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } };
       footnotes1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
       footnotes1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
       footnotes1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
       footnotes1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
       footnotes1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
       footnotes1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
       footnotes1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
       footnotes1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
       footnotes1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
       footnotes1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
       footnotes1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
       footnotes1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
       footnotes1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
       footnotes1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
       footnotes1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

       Footnote footnote1 = new Footnote() { Type = FootnoteEndnoteValues.Separator, Id = -1 };

       Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "003F1A60", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "003F1A60" };

       Run run1 = new Run();
       SeparatorMark separatorMark1 = new SeparatorMark();

       run1.Append(separatorMark1);

       paragraph1.Append(run1);

       footnote1.Append(paragraph1);

       Footnote footnote2 = new Footnote() { Type = FootnoteEndnoteValues.ContinuationSeparator, Id = 0 };

       Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "003F1A60", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "003F1A60" };

       Run run2 = new Run();
       ContinuationSeparatorMark continuationSeparatorMark1 = new ContinuationSeparatorMark();

       run2.Append(continuationSeparatorMark1);

       paragraph2.Append(run2);

       footnote2.Append(paragraph2);

       Footnote footnote3 = new Footnote() { Id = 1 };

       Paragraph paragraph3 = new Paragraph() { RsidParagraphMarkRevision = "009774CC", RsidParagraphAddition = "00626544", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "00626544" };

       ParagraphProperties paragraphProperties1 = new ParagraphProperties();


       ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
       RunFonts runFonts1 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
       FontSize fontSize1 = new FontSize() { Val = "24" };
       FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript() { Val = "24" };

       paragraphMarkRunProperties1.Append(runFonts1);
       paragraphMarkRunProperties1.Append(fontSize1);
       paragraphMarkRunProperties1.Append(fontSizeComplexScript1);
       paragraphProperties1.Append(paragraphMarkRunProperties1);

       Run run3 = new Run() { RsidRunProperties = "009774CC" };

       RunProperties runProperties1 = new RunProperties();
       RunFonts runFonts2 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
       FontSize fontSize2 = new FontSize() { Val = "24" };
       FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript() { Val = "24" };
       VerticalTextAlignment verticalTextAlignment1 = new VerticalTextAlignment() { Val = VerticalPositionValues.Superscript };

       runProperties1.Append(runFonts2);
       runProperties1.Append(fontSize2);
       runProperties1.Append(fontSizeComplexScript2);
       runProperties1.Append(verticalTextAlignment1);
       Text text1 = new Text();
       text1.Text = "1";

       run3.Append(runProperties1);
       run3.Append(text1);

      Run run4 = new Run() { RsidRunProperties = "009774CC" };

       RunProperties runProperties2 = new RunProperties();
       RunFonts runFonts3 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };

       runProperties2.Append(runFonts3);
       Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
       text2.Text = " ";

       run4.Append(runProperties2);
       run4.Append(text2);

      Run run5 = new Run() { RsidRunProperties = "009774CC", RsidRunAddition = "009774CC" };

       RunProperties runProperties3 = new RunProperties();
       RunFonts runFonts4 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
       FontSize fontSize3 = new FontSize() { Val = "21" };
       FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript() { Val = "21" };

       runProperties3.Append(runFonts4);
       runProperties3.Append(fontSize3);
       runProperties3.Append(fontSizeComplexScript3);
       Text text3 = new Text();
       text3.Text = "This is the foot note text";

       run5.Append(runProperties3);
       run5.Append(text3);

       paragraph3.Append(paragraphProperties1);
       paragraph3.Append(run3);
       paragraph3.Append(run4);
       paragraph3.Append(run5);

       footnote3.Append(paragraph3);

       footnotes1.Append(footnote1);
       footnotes1.Append(footnote2);
       footnotes1.Append(footnote3);
       part.Footnotes = footnotes1;
   }

希望这能帮到你!